1.查看是否安装了MySQL,如下所示,安装了下面的Mysql组件
[root@xufeng1-goertek-com tools]# rpm -qa | grep mysql
mysql-community-client-5.7.22-1.el7.x86_64
mysql-community-common-5.7.22-1.el7.x86_64
mysql-community-libs-5.7.22-1.el7.x86_64
mysql-community-libs-compat-5.7.22-1.el7.x86_64
mysql-community-server-5.7.22-1.el7.x86_64
2.查看MySQL服务是否启动,如状态是启动的,请执行关闭命令
[root@xufeng1-goertek-com ~]# service mysqld status
Redirecting to /bin/systemctl status mysqld.service
● mysqld.service - MySQL Server
Loaded: loaded (/usr/lib/systemd/system/mysqld.service; disabled; vendor preset: disabled)
Active: active (running) since Fri 2018-07-20 11:53:54 CST; 4s ago
Docs: man:mysqld(8)
http://dev.mysql.com/doc/refman/en/using-systemd.html
Process: 4091 ExecStart=/usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid $MYSQLD_OPTS (code=exited, status=0/SUCCESS)
Process: 4070 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS)
Main PID: 4095 (mysqld)
CGroup: /system.slice/mysqld.service
└─4095 /usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid
Jul 20 11:53:51 xufeng1-goertek-com systemd[1]: Starting MySQL Server...
Jul 20 11:53:54 xufeng1-goertek-com systemd[1]: Started MySQL Server.
执行关闭命令
[root@xufeng1-goertek-com ~]# service mysqld stop
Redirecting to /bin/systemctl stop mysqld.service
3.卸载MySQL安装的组件
由于Mysql各个组件存在依赖关系,所以要按顺序卸载,否则会出现报错。注意:安装的时候是带rpm后缀的,但是卸载时不带的。下图显示的就是依赖关系报错.
[root@xufeng1-goertek-com ~]# rpm -ev mysql-community-common-5.7.22-1.el7.x86_64
error: Failed dependencies:
mysql-community-common(x86-64) >= 5.7.9 is needed by (installed) mysql-community-libs-5.7.22-1.el7.x86_64
mysql-community-common(x86-64) = 5.7.22-1.el7 is needed by (installed) mysql-community-server-5.7.22-1.el7.x86_64
正常顺序如下:
rpm -ev mysql-community-server-5.7.22-1.el7.x86_64
rpm -ev mysql-community-client-5.7.22-1.el7.x86_64
rpm -ev mysql-community-libs-compat-5.7.22-1.el7.x86_64
rpm -ev mysql-community-libs-5.7.22-1.el7.x86_64
rpm -ev mysql-community-common-5.7.22-1.el7.x86_64
4.卸载完成后使用find命令来查找系统中存在的mysql文件夹,使用rm -rf命令逐个删除文件夹路径即可。
[root@xufeng1-goertek-com ~]# rpm -qa | grep mysql
[root@xufeng1-goertek-com ~]# find / -name mysql
/var/lib/mysql
/var/lib/mysql/mysql
/usr/share/mysql
使用删除命令
rm -rf /var/lib/mysql/
rm -rf /usr/share/mysql/
# 删除日志文件
rm -rf /var/log/mysqld.log
至此,mysql在centos7中完全移除。
作者:xufengzhu
来源:CSDN
原文:https://blog.csdn.net/xufengzhu/article/details/81129863