文章概述
Linux系统下,若要卸载干净默认的MySQL,从而安装新的版本,需要卸载干净,不然会在不经意间影响后续安装
文章演示的系统:Linux CentOS
卸载步骤
1、查询是否安装了MySQL
[root@localhost ~]# rpm -qa | grep mysql
mysql-community-client-5.7.44-1.el7.x86_64
mysql57-community-release-el7-10.noarch
mysql-community-libs-5.7.44-1.el7.x86_64
mysql-community-server-5.7.44-1.el7.x86_64
mysql-community-common-5.7.44-1.el7.x86_64
查询到相关安装包,进行后续卸载
2、查看MySQL服务是否已开启,若开启则需要关闭
[root@localhost ~]# systemctl status mysqld
[root@localhost ~]# systemctl stop mysqld
3、查询含有MySQL的目录并删除
以下是查询结果:
[root@localhost ~]# find / -name mysql
find: ‘/run/user/1000/gvfs’: Permission denied
/etc/logrotate.d/mysql # 删除
/etc/selinux/targeted/active/modules/100/mysql # 删除
/etc/selinux/targeted/tmp/modules/100/mysql # 删除
/root/.virtualenvs/icwp/lib/python3.8/site-packages/django/contrib/gis/db/backends/mysql
/root/.virtualenvs/icwp/lib/python3.8/site-packages/django/db/backends/mysql
/root/mysql
/root/mysql/data/mysql
/var/lib/docker/volumes/f0ece572bc8f6fb3b7448210bb4ead64e622062f7d41e225d17b99659e945b6a/_data/mysql
/var/lib/docker/volumes/58aaeb5cb98e01083d9624bd1981ed4cdf65436d7019b77b471e6bd0cefa9e3b/_data/mysql
/var/lib/docker/overlay2/4f71b050ff227dd296891c0ebd6210744dda330e0a03ec3ed2616c537809ea98/diff/etc/mysql
/var/lib/docker/overlay2/4f71b050ff227dd296891c0ebd6210744dda330e0a03ec3ed2616c537809ea98/diff/usr/bin/mysql
/var/lib/docker/overlay2/4f71b050ff227dd296891c0ebd6210744dda330e0a03ec3ed2616c537809ea98/diff/usr/lib/mysql
/var/lib/docker/overlay2/4f71b050ff227dd296891c0ebd6210744dda330e0a03ec3ed2616c537809ea98/diff/var/lib/mysql
/var/lib/docker/overlay2/71fdf5f5044d7f7a1a6a31b44c1c201abe5ac8d681ee09bf66120a77225d2f66/diff/etc/mysql
/var/lib/mysql # 删除
/var/lib/mysql/mysql # 删除
/usr/bin/mysql # 删除
/usr/lib64/mysql # 删除
/usr/share/mysql # 删除
/usr/local/mysql # 删除
/opt/gitlab/embedded/lib/ruby/gems/3.1.0/gems/activerecord-7.0.8/lib/active_record/connection_adapters/mysql
对于我这台电脑来讲:
-
/var/lib/docker
目录下是docker配置的有关mysql的挂载信息,不用管,不影响安装新版本的MySQL -
/root
目录下的内容,看路径后缀,可以知道是python中django库的相关依赖
上述两个路径下的内容是不用删除的
**一般来说,**Linux默认安装MySQL且有关数据存储的位置,一般是在如下目录下:
-
/var/lib/
目录下 -
/usr/
目录下
一个一个删除上述要删除的目录
rm -rf /var/lib/mysql /var/lib/mysql/mysql /usr/bin/mysql /usr/lib64/mysql /usr/share/mysql /usr/local/mysql
rm -rf /etc/logrotate.d/mysql /etc/selinux/targeted/active/modules/100/mysql /etc/selinux/targeted/tmp/modules/100/mysql
有个目录要注意额外删除!!!
# mysql配置信息所在的目录,这个目录不带mysql字样
rm -rf /etc/my.cnf
4、查询MySQL安装的组件服务,并删除
查询:
[root@localhost ~]# rpm -qa|grep -i mysql
mysql-community-server-5.7.44-1.el7.x86_64
mysql-community-common-5.7.44-1.el7.x86_64
mysql-community-client-5.7.44-1.el7.x86_64
mysql57-community-release-el7-10.noarch
mysql-community-libs-5.7.44-1.el7.x86_64
一个一个删除:文章来源:https://www.toymoban.com/news/detail-795136.html
[root@localhost ~]# rpm -ev mysql-community-server-5.7.44-1.el7.x86_64
[root@localhost ~]# rpm -ev mysql-community-common-5.7.44-1.el7.x86_64
[root@localhost ~]# rpm -ev mysql-community-client-5.7.44-1.el7.x86_64
[root@localhost ~]# rpm -ev mysql57-community-release-el7-10.noarch
[root@localhost ~]# rpm -ev mysql-community-libs-5.7.44-1.el7.x86_64
若上述命令无法删除,改用如下命令:文章来源地址https://www.toymoban.com/news/detail-795136.html
# 若删除不了,改用如下命令
[root@localhost ~]# rpm -ev --nodeps mysql-community-server-5.7.44-1.el7.x86_64
[root@localhost ~]# rpm -ev --nodeps mysql-community-common-5.7.44-1.el7.x86_64
[root@localhost ~]# rpm -ev --nodeps mysql-community-client-5.7.44-1.el7.x86_64
[root@localhost ~]# rpm -ev --nodeps mysql57-community-release-el7-10.noarch
[root@localhost ~]# rpm -ev --nodeps mysql-community-libs-5.7.44-1.el7.x86_64
5、检查是否卸载干净
[root@localhost ~]# rpm -qa | grep -i mysql # 无相关安装
[root@localhost ~]# systemctl start mysql
Failed to start mysql.service: Unit not found. # 证明已卸载干净
到了这里,关于【QA】Linux彻底卸载MySQL的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!