如何在Linux下卸载MySQL数据库呢? 下面总结、整理了一下Linux平台下卸载MySQL的方法。 MySQL的安装主要有三种方式:二进制包安装(Using Generic Binaries)、RPM包安装、源码安装。对应不同的安装方式,卸载的步骤有些不同。文章中如有不足或不对的地方,敬请指出或补充!
RPM包安装方式的MySQL卸载
1: 检查是否安装了MySQL组件。
[root@localhost software]# rpm -qa | grep -i mysql
MySQL-devel-5.6.21-1.rhel5.x86_64
MySQL-client-5.6.21-1.rhel5.x86_64
MySQL-server-5.6.21-1.rhel5.x86_64
如上所示,说明安装了MySQL 5.6.21这个版本的client、server、devel三个组件。
2: 卸载前关闭MySQL服务
2.1 方法1
[root@localhost software]# service mysql status
MySQL running (1907) [ OK ]
[root@localhost software]# service mysql stop
Shutting down MySQL.. [ OK ]
[root@localhost software]# service mysql status
MySQL is not running [FAILED]
[root@localhost software]# chkconfig --list | grep -i mysql
mysql 0:off 1:off 2:on 3:on 4:on 5:on 6:off
3. 收集MySQL对应的文件夹信息
最好实用find命令查看MySQL数据库相关的文件,方便后面彻底删除MySQL。
[root@localhost software]# whereis mysql
mysql: /usr/bin/mysql /usr/lib64/mysql /usr/include/mysql /usr/share/mysql /usr/share/man/man1/mysql.1.gz
[root@localhost software]# find / -name mysql
/var/lib/mysql
/var/lib/mysql/mysql
/usr/lib64/mysql
/usr/include/mysql
/usr/include/mysql/mysql
/usr/share/mysql
/usr/bin/mysql
/etc/logrotate.d/mysql
/etc/rc.d/init.d/mysql
[root@localhost software]#
4: 卸载删除MySQL各类组件
[root@localhost software]# rpm -qa | grep -i mysql
MySQL-devel-5.6.21-1.rhel5.x86_64
MySQL-client-5.6.21-1.rhel5.x86_64
MySQL-server-5.6.21-1.rhel5.x86_64
[root@localhost software]# rpm -ev MySQL-devel-5.6.21-1.rhel5.x86_64
[root@localhost software]# rpm -ev MySQL-client-5.6.21-1.rhel5.x86_64
[root@localhost software]# rpm -ev MySQL-server-5.6.21-1.rhel5.x86_64
5:删除MySQL对应的文件夹
检查各个MySQL文件夹是否清理删除干净。
[root@localhost software]# whereis mysql
mysql: /usr/lib64/mysql
[root@localhost software]# find / -name mysql
/var/lib/mysql
/var/lib/mysql/mysql
/usr/lib64/mysql
[root@localhost software]# rm -rf /usr/lib64/mysql
[root@localhost software]# rm -rf /var/lib/mysql/
6:删除mysql用户及用户组
如果有必要,删除mysql用户以及mysql用户组。
[root@localhost software]# more /etc/passwd | grep mysql
mysql:x:496:493:MySQL server:/var/lib/mysql:/bin/bash
[root@localhost software]# more /etc/shadow | grep mysql
mysql:!!:17295::::::
[root@localhost software]# more /etc/group | grep mysql
mysql:x:493:
[root@localhost software]# userdel mysql
[root@localhost software]# groupdel mysql
groupdel: group 'mysql' does not exist
[root@localhost software]#
7:确认MySQL是否卸载删除
[root@localhost software]# rpm -qa | grep -i mysql
[root@localhost software]#
至此卸载完成
参考:
http://www.cnblogs.com/kerrycode/p/4364465.html