MySQL8.0降级为MySQL5.7
OS:centos 7.6
注:更换之前需做好数据库文件的备份
一、卸载MySQL8.0
rpm -qa | grep -i mysql
yum -y remove mysql80-community-release-el7-1.noarch
yum -y remove mysql-community-server-8.0.20-1.el7.x86_64
yum -y remove mysql-community-common-8.0.20-1.el7.x86_64
二、安装MySQL5.7
1.下载最新的源码:
wget https://dev.mysql.com/get/mysql80-community-release-el7-1.noarch.rpm
2.安装源码
rpm -Uvh mysql80-community-release-el7-1.noarch.rpm
3.查看所有MySQL包
yum repolist all | grep mysql
4.禁用MySQL8.0版本,启用MySQL5.7版本
yum -y install yum-utils #安装yum管理工具,系统默认不安装
yum-config-manager --disable mysql80-community
yum-config-manager --enable mysql57-community
当enabled=1时,是启用的;当enabled=0时,是禁用的。也可以进入/etc/yum.repos.d/mysql-community.repo 进行修改设置
5.检查现在可用版本
yum repolist enabled | grep mysql
6.等待安装
yum install mysql-community-server
mysql --version
7.开启服务
systemctl start mysqld
systemctl enable mysqld
注:若开启失败,需在/var/lib/mysql下新建data目录,并修改/etc/my.cnf文件对应配置“ datadir=/var/lib/mysql/data”,再次尝试开启服务
三、启动后配置
1.更改MySQL密码
grep 'temporary password' /var/log/mysqld.log
mysql -u root -p'初始密码'
ALTER USER 'root'@'localhost' IDENTIFIED BY '123456';
2.允许root用户远程连接
use mysql;
select host, user, authentication_string, plugin from user;
update user set host = "%" where user = "root";
flush privileges;
测试连接并导入已备份数据库
参考文档:
https://blog.csdn.net/toooooop8/article/details/103851738( MySQL导入数据库版本不兼容处理方法)