参考:
https://www.cnblogs.com/alan-lin/p/9950389.html
https://blog.csdn.net/weixin_36354744/article/details/113599916
https://www.cnblogs.com/liuxgcn/p/11115252.html
Mysql的repo资源地址
http://repo.mysql.com/
下载mysql-community-release-el7.rpm
wget http://repo.mysql.com/mysql-community-release-el7.rpm
最早在服务器上安装了mysql8,后来想替换成mysql5.6
卸载mysql前,先查看下/etc/my.cnf 中datadir对应的地址,在卸载mysql之后,需要清空数据文件,否则低版本的mysql启动会有问题
曾经安装过mysql80-community-release-el7-3.noarch.rpm
在执行
yum repolist all | grep mysql
查看mysql存储库发现并没有其他版本
[root@iZ2ze43g5psp0lxiuxelzjZ app]# yum repolist all | grep mysql
mysql-cluster-8.0-community MySQL Cluster 8.0 Community disabled
mysql-cluster-8.0-community-source MySQL Cluster 8.0 Community - Source disabled
mysql-connectors-community MySQL Connectors Community enabled
mysql-connectors-community-source MySQL Connectors Community - Source disabled
mysql-tools-community MySQL Tools Community enabled
mysql-tools-community-source MySQL Tools Community - Source disabled
mysql-tools-preview MySQL Tools Preview disabled
mysql-tools-preview-source MySQL Tools Preview - Source disabled
mysql80-community MySQL 8.0 Community Server disabled
mysql80-community-source MySQL 8.0 Community Server - Source disabled
于是尝试安装了mysql-community-release-el7-7.noarch.rpm
发现虽然有了mysql56-community-source,但是并没有mysql56-community
[root@iZ2ze43g5psp0lxiuxelzjZ app]# yum repolist all | grep mysql
mysql-cluster-7.5-community-source MySQL Cluster 7.5 Community - Source disabled
mysql-cluster-7.6-community-source MySQL Cluster 7.6 Community - Source disabled
mysql-cluster-8.0-community MySQL Cluster 8.0 Community disabled
mysql-cluster-8.0-community-source MySQL Cluster 8.0 Community - Source disabled
mysql-connectors-community MySQL Connectors Community enabled
mysql-connectors-community-source MySQL Connectors Community - Source disabled
mysql-tools-community MySQL Tools Community enabled
mysql-tools-community-source MySQL Tools Community - Source disabled
mysql-tools-preview MySQL Tools Preview disabled
mysql-tools-preview-source MySQL Tools Preview - Source disabled
mysql55-community-source MySQL 5.5 Community Server - Source disabled
mysql56-community-source MySQL 5.6 Community Server - Source disabled
mysql57-community-source MySQL 5.7 Community Server - Source disabled
mysql80-community MySQL 8.0 Community Server disabled
mysql80-community-source MySQL 8.0 Community Server - Source disabled
查了很多解决方案最后通过这篇文章https://www.cnblogs.com/liuxgcn/p/11115252.html
执行
[root@iZ2ze43g5psp0lxiuxelzjZ app]# yum clean all
59 files removed
[root@iZ2ze43g5psp0lxiuxelzjZ app]# yum makecache
CentOS-8 - AppStream 34 MB/s | 6.3 MB 00:00
CentOS-8 - Base 13 MB/s | 2.3 MB 00:00
CentOS-8 - Extras 98 kB/s | 9.6 kB 00:00
Extra Packages for Enterprise Linux 8 - x86_64 43 MB/s | 9.3 MB 00:00
MySQL Connectors Community 62 kB/s | 56 kB 00:00
MySQL Tools Community 192 kB/s | 230 kB 00:01
Metadata cache created.
两条命令,并且卸载了mysql80-community-release-el7-3.noarch.rpm
[root@iZ2ze43g5psp0lxiuxelzjZ app]# rpm -e mysql80-community-release-el7-3.noarch
warning: /etc/yum.repos.d/mysql-community.repo saved as /etc/yum.repos.d/mysql-community.repo.rpmsave
下载安装mysql-community-release-el7.rpm后终于出现了需要的版本
[root@iZ2ze43g5psp0lxiuxelzjZ app]# rpm -ivh mysql-community-release-el7.rpm
Verifying... ################################# [100%]
Preparing... ################################# [100%]
Updating / installing...
1:mysql80-community-release-el7-3 ################################# [100%]
[root@iZ2ze43g5psp0lxiuxelzjZ app]# yum repolist all | grep mysql
mysql-cluster-7.5-community MySQL Cluster 7.5 Community disabled
mysql-cluster-7.5-community-source MySQL Cluster 7.5 Community - Source disabled
mysql-cluster-7.6-community MySQL Cluster 7.6 Community disabled
mysql-cluster-7.6-community-source MySQL Cluster 7.6 Community - Source disabled
mysql-cluster-8.0-community MySQL Cluster 8.0 Community disabled
mysql-cluster-8.0-community-source MySQL Cluster 8.0 Community - Source disabled
mysql-connectors-community MySQL Connectors Community enabled
mysql-connectors-community-source MySQL Connectors Community - Source disabled
mysql-tools-community MySQL Tools Community enabled
mysql-tools-community-source MySQL Tools Community - Source disabled
mysql-tools-preview MySQL Tools Preview disabled
mysql-tools-preview-source MySQL Tools Preview - Source disabled
mysql55-community MySQL 5.5 Community Server disabled
mysql55-community-source MySQL 5.5 Community Server - Source disabled
mysql56-community MySQL 5.6 Community Server disabled
mysql56-community-source MySQL 5.6 Community Server - Source disabled
mysql57-community MySQL 5.7 Community Server disabled
mysql57-community-source MySQL 5.7 Community Server - Source disabled
mysql80-community MySQL 8.0 Community Server enabled
mysql80-community-source MySQL 8.0 Community Server - Source disabled
修改各个版本的可用状态
[root@iZ2ze43g5psp0lxiuxelzjZ app]# yum-config-manager --disable mysql80-community
[root@iZ2ze43g5psp0lxiuxelzjZ app]# yum-config-manager --disable mysql57-community
[root@iZ2ze43g5psp0lxiuxelzjZ app]# yum-config-manager --enable mysql56-community
[root@iZ2ze43g5psp0lxiuxelzjZ app]# yum repolist all | grep mysql
mysql-cluster-7.5-community MySQL Cluster 7.5 Community disabled
mysql-cluster-7.5-community-source MySQL Cluster 7.5 Community - Source disabled
mysql-cluster-7.6-community MySQL Cluster 7.6 Community disabled
mysql-cluster-7.6-community-source MySQL Cluster 7.6 Community - Source disabled
mysql-cluster-8.0-community MySQL Cluster 8.0 Community disabled
mysql-cluster-8.0-community-source MySQL Cluster 8.0 Community - Source disabled
mysql-connectors-community MySQL Connectors Community enabled
mysql-connectors-community-source MySQL Connectors Community - Source disabled
mysql-tools-community MySQL Tools Community enabled
mysql-tools-community-source MySQL Tools Community - Source disabled
mysql-tools-preview MySQL Tools Preview disabled
mysql-tools-preview-source MySQL Tools Preview - Source disabled
mysql55-community MySQL 5.5 Community Server disabled
mysql55-community-source MySQL 5.5 Community Server - Source disabled
mysql56-community MySQL 5.6 Community Server enabled
mysql56-community-source MySQL 5.6 Community Server - Source disabled
mysql57-community MySQL 5.7 Community Server disabled
mysql57-community-source MySQL 5.7 Community Server - Source disabled
mysql80-community MySQL 8.0 Community Server disabled
mysql80-community-source MySQL 8.0 Community Server - Source disabled
安装
[root@iZ2ze43g5psp0lxiuxelzjZ app]# yum install mysql-community-server
......
Installing:
mysql-community-server x86_64 5.6.51-2.el7 mysql56-community 67 M
Installing dependencies:
mysql-community-client x86_64 5.6.51-2.el7 mysql56-community 21 M
mysql-community-common x86_64 5.6.51-2.el7 mysql56-community 287 k
mysql-community-libs x86_64 5.6.51-2.el7 mysql56-community 2.2 M
......
Installed:
mysql-community-client-5.6.51-2.el7.x86_64 mysql-community-common-5.6.51-2.el7.x86_64 mysql-community-libs-5.6.51-2.el7.x86_64 mysql-community-server-5.6.51-2.el7.x86_64
Complete!
[root@iZ2ze43g5psp0lxiuxelzjZ app]# rpm -qa | grep mysql
mysql-community-client-5.6.51-2.el7.x86_64
mysql80-community-release-el7-3.noarch
mysql-community-libs-5.6.51-2.el7.x86_64
mysql-community-server-5.6.51-2.el7.x86_64
mysql-community-common-5.6.51-2.el7.x86_64
[root@iZ2ze43g5psp0lxiuxelzjZ app]# mysql -V
mysql Ver 14.14 Distrib 5.6.51, for Linux (x86_64) using EditLine wrapper
安装成功但是启动的时候发现一直没有反应
猜测可能是之前高版本的数据文件还在,先删除数据文件再次启动,启动成功
[root@iZ2ze43g5psp0lxiuxelzjZ lib]# service mysqld restart
Redirecting to /bin/systemctl restart mysqld.service
安装成功