服务器环境:centos7.4.14
问题:mysql无法正常启动
查看日志
2018-02-23T02:10:08.371209Z 0 [System] [MY-010116] /usr/sbin/mysqld (mysqld 8.0.4-rc-log) starting as process 27702 ...
2018-02-23T02:10:08.737713Z 1 [ERROR] [MY-011096] No data dictionary version number found.
2018-02-23T02:10:08.737989Z 0 [ERROR] [MY-010020] Data Dictionary initialization failed.
2018-02-23T02:10:08.738038Z 0 [ERROR] [MY-010119] Aborting
后来发现,升级后默认启用了caching_sha2_password身份认证机制,以前的数据是不能直接运行的。
只能先恢复原版本,将数据从原版本导出,重新导入使用,或再升级导入。
一、卸载8.0.4
备份数据
mv /var/lib/{mysql,mysql.bak}
chown -R mysql:mysql /var/lib/mysql.bak
chmod 755 -R /var/lib/mysql.bak
直接yum卸载
rpm -qa|grep ‘^mysql‘
然后将查询出的8.0.4的包全部yum卸载
二、安装8.0.3
从官方下载 8.0.3
https://downloads.mysql.com/archives/community/
下载打包版mysql-8.0.3-0.1.rc.el7.x86_64.rpm-bundle.tar
解压
tar -xvf mysql-8.0.3-0.1.rc.el7.x86_64.rpm-bundle.tar
然后依次安装common、libs、client、server
rpm -ivh mysql-community-common-8.0.3-0.1.rc.el7.x86_64.rpm
rpm -ivh mysql-community-libs-8.0.3-0.1.rc.el7.x86_64.rpm
rpm -ivh mysql-community-client-8.0.3-0.1.rc.el7.x86_64.rpm
rpm -ivh mysql-community-server-8.0.3-0.1.rc.el7.x86_64.rpm
启动mysql
systemctl start msyqld.service
此时/var/lib/重新生成了一个新的mysql文件夹
三、数据导出
修改/etc/my.cnf
指向旧数据
[mysqld]
innodb_force_recovery = 6
datadir=/var/lib/mysql.bak
Forcing InnoDB Recovery提供了6个等级的修复模式
innodb_force_recovery 参考: http://blog.csdn.net/weitao_11/article/details/55050200
全库导出:
mysqldump -uroot -p --all-databases > /home/sqlfile.sql
四、数据恢复
修改/etc/my.cnf
数据路径,去掉修复模式,修复模式下不可写
[mysqld]
datadir=/var/lib/mysql
查看临时密码
[[email protected]]# cat /var/log/mysqld.log|grep password
2018-02-23T08:06:36.785974Z 5 [Note] A temporary password is generated for [email protected]: Leyk2qO_75ER
用临时密码登录mysql,修改密码
放弃升级,直接导入数据
mysql -uroot -p
mysql>GRANT ALL PRIVILEGES ON *.* TO ‘root‘@‘localhost‘ IDENTIFIED BY ‘[email protected]‘ WITH GRANT OPTION;
mysql>flush privileges;
mysql>source /home/sqlfile.sql;
重启后,一切正常。升级前一定要备份,一定要经常备份。
原文地址:http://blog.51cto.com/2884868/2072436
时间: 2024-11-08 17:13:43