一、備份數據庫,升級MySQL一般不會丟失數據,但保險起見,咱們須要作這一步。輸入命令:mysql
mysqldump -u xxx -h xxx -P 3306 -p --all-databases > databases.sql
二、中止MySQL服務,輸入命令:sql
service mysqld stop
三、 卸載舊版MySQL,輸入命令:數據庫
yum remove mysql mysql-*
執行過程當中會詢問你是否移除,此時輸入「Y」安全
查看已安裝的軟件:ide
rpm -qa¦grep mysql
卸載mysql:this
yum remove mysql mysql-server mysql-libs compat-mysql51
四、移除命令執行後,可再看看是否有殘餘的mysql,輸入命令:code
yum list installed | grep mysql
若是有,可輸入命令刪除:server
yum remove mysql-libs
五、下載安裝最新的rpm文件。事件
這步要看你須要什麼文件,我安裝的是:mysql57-community-release-el6-7.noarch.rpm(若是提早獲得了這個文件,第6步能夠使用yum localinstall mysql57-community-release-el6-7.noarch.rpm從本地安裝)ssl
rpm -Uvh http://repo.mysql.com/mysql-community-release-el6-5.noarch.rpm
六、安裝MySQL,輸入命令(過程當中問詢是否yes,一路y下去):
yum install mysql-community-server
七、安裝完成後,輸入命令查看MySQL版本號:
mysql -V
8 、啓動MySQL,輸入命令:
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
九、進入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)
十、設置mysql爲開機啓動
chkconfig --list 顯示服務列表
若是看到mysqld的服務,而且3,4,5都是on的話則成功,若是是off,則鍵入
chkconfig --level 345 mysqld on
reboot重啓電腦
netstat -na | grep 3306,若是看到有監據說明服務啓動了。也能夠用:service mysqld status看狀態