1、備份數據庫,升級MySQL通常不會丟失數據,但保險起見,我們需要做這一步。輸入命令:
mysqldump -u xxx -h xxx -P 3306 -p --all-databases > databases.sql

-
service mysqld stop
-
yum remove mysql mysql-*
執行過程中會詢問你是否移除,此時輸入“Y”
查看已安裝的軟件:rpm -qa¦grep mysql
卸載mysql:yum remove mysql mysql-server mysql-libs compat-mysql51
-
yum list installed | grep mysql
如果有,可輸入命令刪除:
yum remove mysql-libs
-
這步要看你需要什么文件,我安裝的是:mysql57-community-release-el6-7.noarch.rpm(如果提前得到了這個文件,第6步可以使用yum localinstall
mysql57-community-release-el6-7.noarch.rpm從本地安裝)rpm -Uvh http://repo.mysql.com/mysql-community-release-el6-5.noarch.rpm
-
yum install mysql-community-server
-
mysql -V
-
service mysqld start
第一次啟動比較慢,因為它會自己做初始化,耐心等待即可。如果啟動失敗,提示“MySQL Daemon failed to start”,可以嘗試先初始化mysql,輸入命令:mysqld --initialize。如果初始化提示:2015-12-22T07:49:45.386095Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2015-12-22T07:49:45.388125Z 0 [ERROR] --initialize specified but the data directory has files in it. Aborting.
2015-12-22T07:49:45.388153Z 0 [ERROR] Aborting說明數據文件夾已被創建,直接刪除,讓mysql自己創建即可,輸入命令:rm -rf /var/lib/mysql刪除后,注意:然后不需要再初始化了,直接啟動mysql,它會自己初始化,輸入命令:service mysqld start
9、進入mysql后,第一件事件就是要你改默認密碼。mysql 5.7以后,系統自動生成隨機的密碼,我操作時,沒登錄上,切換mysql到安全模式啟動,自己去修改即可(安全模式修改密碼,見另一篇文章:MySQL忘記密碼,或:root密碼重置報錯:mysqladmin: connect to server at 'localhost' failed的解決方案)。
[root@c12 mysql57]# ./bin/mysql -u root -p
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.
mysql> alter user root identified by 'root';
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.使用mysqladmin總算能改了
[root@c12 mysql57]# ./bin/mysqladmin -u root -p password
Enter password:
New password:
Confirm new password:
Warning: Since password will be sent to server in plain text, use ssl connection to ensure password safety.mysql> select version();
+-----------+
| version() |
+-----------+
| 5.7.8-rc |
+-----------+
1 row in set (0.00 sec)10、設置mysql為開機啟動
chkconfig --list 顯示服務列表
如果看到mysqld的服務,並且3,4,5都是on的話則成功,如果是off,則鍵入
chkconfig --level 345 mysqld on
reboot重啟電腦
netstat -na | grep 3306,如果看到有監聽說明服務啟動了。也可以用:service mysqld status看狀態