Linux彻底删除MySQL
注意:在安装另一个MySQL版本之前一定要把之前MySQL版本给卸载干净。
详细步骤如下:
1、检查云服务器是否已经安装了MySQL:
rpm -qa | grep mysql
如下所示:
mysql-community-release-el7-5.noarchmysql-community-libs-5.6.51-2.el7.x86_64mysql-community-client-5.6.51-2.el7.x86_64mysql-community-server-5.6.51-2.el7.x86_64mysql-community-common-5.6.51-2.el7.x86_64
2、查看MySQL服务是否开启:
systemctl status mysqld
如开启则须关闭,关闭MySQL服务:
systemctl stop mysqld
3、查找含有MySQL的目录:
find / -name mysql
如下所示:
/var/lib/mysql/var/lib/mysql/mysql/usr/local/mysql/usr/lib64/mysql/usr/share/mysql/usr/bin/mysql/etc/logrotate.d/mysql/etc/selinux/targeted/active/modules/100/mysql
4、删除含有MySQL的目录,依次删除目录(根据自己查找出来的目录进行依次删除):
rm -rf /var/lib/mysqlrm -rf /var/lib/mysql/mysqlrm -rf /usr/local/mysqlrm -rf /usr/lib64/mysqlrm -rf /usr/share/mysqlrm -rf /usr/bin/mysqlrm -rf /etc/logrotate.d/mysqlrm -rf /etc/selinux/targeted/active/modules/100/mysql
注意:上面执行完后/etc/my.cnf不会删除掉,需要手动单独删除。
rm -rf /etc/my.cnf
5、查找MySQL安装的组件服务:
rpm -qa|grep -i mysql
如下所示:
mysql-community-release-el7-5.noarchmysql-community-libs-5.6.51-2.el7.x86_64mysql-community-client-5.6.51-2.el7.x86_64mysql-community-server-5.6.51-2.el7.x86_64mysql-community-common-5.6.51-2.el7.x86_64
6、卸载并删除查找出来的组件服务,依次删除目录(根据自己查找出来的目录进行依次删除):
rpm -ev mysql-community-release-el7-5.noarchrpm -ev mysql-community-server-5.6.51-2.el7.x86_64rpm -ev mysql-community-client-5.6.51-2.el7.x86_64rpm -ev mysql-community-libs-5.6.51-2.el7.x86_64rpm -ev mysql-community-common-5.6.51-2.el7.x86_64
如果删除不了则加上--nodeps。例如:rpm -ev --nodeps mysql-community-libs-5.6.51-2.el7.x86_64
7、卸载完成后检查是否卸载成功:
rpm -qa | grep -i mysql
systemctl start mysql
如提示
Failed to start mysql.service: Unit not found.
则说明此时已尽卸载干净了。
来源地址:https://blog.csdn.net/Turniper/article/details/130397482