在虛擬機上安裝mysql走了不少彎路,在此備份。。。
首先感謝下這幾篇博客提供的幫助:
https://www.cnblogs.com/pythonal/p/6141516.html
http://blog.csdn.net/typa01_kk/article/details/49059729
http://blog.csdn.net/skywalker_leo/article/details/47274441
1.官網下載mysql:
mysql-5.7.20-1.el7.x86_64.rpm-bundle.tar
mysql分了好多版本,有linux和ubuntu等等的,個人感覺最方便的是紅帽;
2.解壓:
tar -xvf mysql-版本號

解壓后有很多個,但是我們只需要安裝4個(有項目依賴,需要關注下順序);
3.安裝:
安裝前先卸載自帶的mariadb-lib(必須卸載,不然會碰到依賴錯誤,別問我怎么知道的。。。)
備注:如果刪不掉的話可以試試這條命令:yum remove mysql-libs
然后依次安裝:
#rpm -ivh mysql-community-common-版本.el6.x86_64.rpm
#rpm -ivh mysql-community-libs-版本.el6.x86_64.rpm
#rpm -ivh mysql-community-client-版本.el6.x86_64.rpm
#rpm -ivh mysql-community-server-版本.el6.x86_64.rpm
4.數據庫初始化:
為了保證數據庫目錄為與文件的所有者為 mysql 登陸用戶,如果你是以 root 身份運行 mysql 服務,需要執行下面的命令初始化
mysqld --initialize --user=mysql
systemctl start mysqld.service
mysql -uroot -p
第一次不用輸入密碼直接登錄,如果輸入密碼了或者碰到如下錯誤:
Access denied for user 'root'@'localhost' (using password:YES)
請參考這篇博客解決:
http://blog.csdn.net/skywalker_leo/article/details/47274441;
[root@wshCentOS ~]# mysql -uroot -proot123
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 19538
Server version: 5.7.20 MySQL Community Server (GPL)
Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql>
修改之后登錄成功,可能需要重置密碼;
以上;
