【QA】Linux-CentOS彻底卸载MySQL

文章概述

Linux系统下,若要卸载干净默认的MySQL,从而安装新的版本,需要卸载干净,不然会在不经意间影响后续安装

文章演示的系统:Linux CentOS

卸载步骤

1、查询是否安装了MySQL

sh 复制代码
[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服务是否已开启,若开启则需要关闭

sh 复制代码
[root@localhost ~]# systemctl status mysqld
[root@localhost ~]# systemctl stop mysqld

3、查询含有MySQL的目录并删除

以下是查询结果:

sh 复制代码
[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/目录下

一个一个删除上述要删除的目录

sh 复制代码
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

有个目录要注意额外删除!!!

sh 复制代码
# mysql配置信息所在的目录,这个目录不带mysql字样
rm -rf /etc/my.cnf

4、查询MySQL安装的组件服务,并删除

查询:

sh 复制代码
[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

一个一个删除:

sh 复制代码
[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

若上述命令无法删除,改用如下命令:

sh 复制代码
# 若删除不了,改用如下命令
[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、检查是否卸载干净

sh 复制代码
[root@localhost ~]# rpm -qa | grep -i mysql		# 无相关安装
[root@localhost ~]# systemctl start mysql
Failed to start mysql.service: Unit not found.	# 证明已卸载干净
相关推荐
xoxo-Rachel5 分钟前
(超级详细!!!)解决“com.mysql.jdbc.Driver is deprecated”警告:详解与优化
java·数据库·mysql
blessing。。23 分钟前
I2C学习
linux·单片机·嵌入式硬件·嵌入式
2202_7544215438 分钟前
生成MPSOC以及ZYNQ的启动文件BOOT.BIN的小软件
java·linux·开发语言
JH307339 分钟前
Oracle与MySQL中CONCAT()函数的使用差异
数据库·mysql·oracle
运维&陈同学1 小时前
【zookeeper03】消息队列与微服务之zookeeper集群部署
linux·微服务·zookeeper·云原生·消息队列·云计算·java-zookeeper
周末不下雨2 小时前
win11+ubuntu22.04双系统 | 联想 24 y7000p | ubuntu 22.04 | 把ubuntu系统装到1T的移动固态硬盘上!!!
linux·运维·ubuntu
路有瑶台2 小时前
MySQL数据库学习(持续更新ing)
数据库·学习·mysql
lwprain3 小时前
常用docker应用部署,wordpress、mysql、tomcat、nginx、redis
mysql·docker·tomcat
哎呦喂-ll3 小时前
Linux进阶:环境变量
linux