centos7彻底删除mysql8.0重装mysql5.7操作详解

最近鼓捣mysql8.0的时候出现一些兼容性问题,看来太新的东西还是悠着点用。这里记录下彻底删除mysql8.0重新安装mysql5.7的一些操作。

我是T型人小付,一位坚持终身学习的互联网从业者。喜欢我的博客欢迎在csdn上关注我,如果有问题欢迎在底下的评论区交流,谢谢。

操作环境

  • centos 7
  • mysql 8.0

卸载mysql8.0

删除已安装的mysql包

因为这个mysql是直接用yum安装的,所以删除过程容易不少。

想查看centos7安装mysql8.0过程的移步 《rpm,repo和yum的区别和使用详解(centos7安装和升级mysql举例)》

查找下安装的包

[root@testmachine fuhx]# yum list installed | grep mysql
mysql-community-client.x86_64           8.0.19-1.el7                   @mysql80-community
mysql-community-common.x86_64           8.0.19-1.el7                   @mysql80-community
mysql-community-libs.x86_64             8.0.19-1.el7                   @mysql80-community
mysql-community-server.x86_64           8.0.19-1.el7                   @mysql80-community
mysql80-community-release.noarch        el7-3                          installed

其中前面4个是安装的软件包,最后一个是官方的repo安装包。注意,repo文件还是可以用之前安装的8.0的,因为一个文件里面包含所有历史版本的repo地址,只需要enable特定版本即可,见下面操作

分别将前面4个包删除

[root@testmachine fuhx]# yum remove xxxxxxx

删除残留文件夹

查找所有mysql残留文件夹,强行删除

[root@testmachine fuhx]# find / -name mysql

一般情况下只有下面三个文件夹要删除

/var/lib/mysql
/var/lib/mysql/mysql
/usr/share/mysql

直接rm -rf删除即可。此为高危操作,请仔细检查命令再执行

删除配置文件

mysql的配置文件一般是/etc/my.cnf,如果没有被自动删除则手动删除一下。

安装mysql5.7

修改repo版本

如上面所述,mysql官方提供的repo文件/etc/yum.repos.d/mysql-community.repo包含所有历史版本的repo地址,只需要将特定版本进行enable即可。这里将8.0的repo禁用,然后启用5.7即可,如下

# Enable to use MySQL 5.7
[mysql57-community]
name=MySQL 5.7 Community Server
baseurl=http://repo.mysql.com/yum/mysql-5.7-community/el/7/$basearch/
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql

[mysql80-community]
name=MySQL 8.0 Community Server
baseurl=http://repo.mysql.com/yum/mysql-8.0-community/el/7/$basearch/
enabled=0
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql

开始安装

直接用yum进行安装

[root@testmachine etc]# yum -y install mysql-community-server

验证安装

启用mysqld服务

[root@testmachine etc]# systemctl start mysqld

尝试连接,可能会遇到下面的报错

[root@testmachine etc]# mysql -u root
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)

按照另一篇博客《entos7安装完mysql5.7.29访问报错解决办法》来解决。

修改完密码再次尝试连接,成功

[root@testmachine etc]# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.29 MySQL Community Server (GPL)

Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql>
  • 1
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值