Linux下彻底卸载MySQL数据库

一、检查服务器是否已经安装了MySQL

rpm -qa|grep mysql
如下所示
mysql-community-libs-compat-8.1.0-1.el7.x86_64
mysql-community-server-8.1.0-1.el7.x86_64
mysql-community-icu-data-files-8.1.0-1.el7.x86_64
mysql-community-common-8.1.0-1.el7.x86_64
php-mysqlnd-7.3.33-1.el7.remi.x86_64
mysql-community-libs-8.1.0-1.el7.x86_64
mysql-community-client-plugins-8.1.0-1.el7.x86_64
mysql-community-client-8.1.0-1.el7.x86_64

二、查看MySQL服务是否开启

systemctl status mysqld
如下所示:
mysqld.service - MySQL Server
   Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
   Active: active (running) since Tue 2024-02-20 15:24:50 CST; 9s ago
     Docs: man:mysqld(8)
           http://dev.mysql.com/doc/refman/en/using-systemd.html
  Process: 30152 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS)
 Main PID: 30194 (mysqld)
   Status: "Server is operational"
    Tasks: 38
   CGroup: /system.slice/mysqld.service
           └─30194 /usr/sbin/mysqld

Feb 20 15:24:45 i2MaskingCtrl systemd[1]: Starting MySQL Server...
Feb 20 15:24:50 i2MaskingCtrl systemd[1]: Started MySQL Server.

如开启则关闭MySQL服务,执行以下命令:

systemctl stop mysqld

三、查找含有MySQL的目录

find / -name mysql
如下所示:
/etc/logrotate.d/mysql
/var/lib/mysql
/var/lib/mysql/mysql
/usr/bin/mysql
/usr/lib64/mysql

根据自己查找出来的目录进行依次删除:

rm -rf /etc/logrotate.d/mysql /var/lib/mysql /var/lib/mysql/mysql /usr/bin/mysql /usr/lib64/mysql

还需删除以下两个目录:

//mysql的配置文件
rm -rf /etc/my.cnf
//如果不删除这个文件,则重新安装的Mysql将无法设置password
rm -rf /var/log/mysqld.log

四、查找MySQL安装的组件服务

rpm -qa|grep -i mysql
如下所示:
mysql-community-libs-compat-8.1.0-1.el7.x86_64
mysql-community-server-8.1.0-1.el7.x86_64
mysql-community-icu-data-files-8.1.0-1.el7.x86_64
mysql-community-common-8.1.0-1.el7.x86_64
php-mysqlnd-7.3.33-1.el7.remi.x86_64
mysql-community-libs-8.1.0-1.el7.x86_64
mysql-community-client-plugins-8.1.0-1.el7.x86_64
mysql-community-client-8.1.0-1.el7.x86_64

卸载并删除查找出来的组件服务:

rpm -ev mysql-community-libs-compat-8.1.0-1.el7.x86_64
rpm -ev mysql-community-server-8.1.0-1.el7.x86_64
rpm -ev mysql-community-icu-data-files-8.1.0-1.el7.x86_64
rpm -ev mysql-community-common-8.1.0-1.el7.x86_64
rpm -ev mysql-community-libs-8.1.0-1.el7.x86_64
rpm -ev mysql-community-client-plugins-8.1.0-1.el7.x86_64
rpm -ev mysql-community-client-8.1.0-1.el7.x86_64

注:如果删除不了则加上--nodeps。例如:rpm -ev --nodeps mysql-community-libs-compat-8.1.0-1.el7.x86_64

五、卸载完成后检查是否卸载成功

rpm -qa|grep -i mysql
php-mysqlnd-7.3.33-1.el7.remi.x86_64
systemctl start mysql
如报错Failed to start mysql.service: Unit not found.
则说明此时mysql已经卸载干净了。
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值