centOS 6.5下升级mysql,从5.1升级到5.7
1、备份数据库,升级MysqL通常不会丢失数据,但保险起见,我们需要做这一步。输入命令:
MysqLdump -u xxx -h xxx -P 3306 -p --all-databases > databases.sql
-
service MysqLd stop
-
执行过程中会询问你是否移除,此时输入“Y”
查看已安装的软件:rpm -qa¦grep MysqL
卸载MysqL:yum remove MysqL MysqL-server MysqL-libs compat-MysqL51
-
这步要看你需要什么文件,我安装的是: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
第一次启动比较慢,因为它会自己做初始化,耐心等待即可。如果初始化提示: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,它会自己初始化,输入命令: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,如果看到有监听说明服务启动了。也可以用:serviceMysqLdstatus看状态