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看状态