Linux卸载原生MySQL数据库

在安装Linux系统时,如果同时选择安装MySQL数据库,则默认是5.1版本,这对于目前新上线的生产系统而言,数据库版本太低。因此就需要卸载原生MySQL数据库,安装功能及稳定性更好的5.5或5.6版本。
卸载原生MySQL请参考潇湘隐者的文章《Linux平台卸载MySQL总结》http://www.cnblogs.com/kerrycode/p/4364465.html

1.检查是否安装了MySQL组件
[root@dbtest5 ~]# rpm -qa|grep -i mysql
mysql-5.1.73-3.el6_5.x86_64
mysql-server-5.1.73-3.el6_5.x86_64
mysql-libs-5.1.73-3.el6_5.x86_64
perl-DBD-MySQL-4.013-3.el6.x86_64
以上显示,说明安装了MySQL 5.1.73这个版本的server、devel、libs、perl-DBD四个组件。

2.关闭MySQL服务
--- 方式1
[root@dbtest5 ~]# service mysqld status
mysqld (pid  29140) is running...
[root@dbtest5 ~]# service mysqld stop
Stopping mysqld:                                           [  OK  ]
[root@dbtest5 ~]# service mysqld status
mysqld is stopped
--- 方式2 
[root@dbtest5 ~]# /etc/init.d/mysqld start
Starting mysqld:                                           [  OK  ]
[root@dbtest5 ~]# /etc/init.d/mysqld status
mysqld (pid  29630) is running...
[root@dbtest5 ~]# /etc/init.d/mysqld stop
Stopping mysqld:                                           [  OK  ]
[root@dbtest5 ~]# /etc/init.d/mysqld status
mysqld is stopped

3.收集MySQL对应的文件信息
[root@dbtest5 ~]# whereis mysql
mysql: /usr/bin/mysql /usr/lib64/mysql /usr/share/mysql /usr/share/man/man1/mysql.1.gz
[root@dbtest5 ~]# which mysql
/usr/bin/mysql
[root@dbtest5 ~]# find / -name mysql
/usr/share/mysql
/usr/bin/mysql
/usr/lib64/mysql
/usr/lib64/perl5/auto/DBD/mysql
/usr/lib64/perl5/DBD/mysql
/var/lib/mysql
/var/lib/mysql/mysql

4.卸载删除MySQL组件
[root@dbtest5 ~]# rpm -ev mysql-server-5.1.73-3.el6_5.x86_64
warning: /var/log/mysqld.log saved as /var/log/mysqld.log.rpmsave
[root@dbtest5 ~]# rpm -ev mysql-5.1.73-3.el6_5.x86_64
[root@dbtest5 ~]# rpm -ev perl-DBD-MySQL-4.013-3.el6.x86_64
[root@dbtest5 ~]# rpm -ev mysql-libs-5.1.73-3.el6_5.x86_64
error: Failed dependencies:
        libmysqlclient.so.16()(64bit) is needed by (installed) postfix-2:2.6.6-6.el6_5.x86_64
        libmysqlclient.so.16(libmysqlclient_16)(64bit) is needed by (installed) postfix-2:2.6.6-6.el6_5.x86_64
        mysql-libs is needed by (installed) postfix-2:2.6.6-6.el6_5.x86_64
由于包依赖性关系,卸载mysql-libs包时出错,这里可以加--nodeps参数强制卸载:
[root@dbtest5 ~]# rpm -ev mysql-libs-5.1.73-3.el6_5.x86_64 --nodeps
到此MySQL组件已经全部卸载,使用rpm -qa|grep -i mysql确认所有组件包均已卸载
[root@dbtest5 ~]# rpm -qa|grep -i mysql

5.删除MySQL对于的文件
[root@dbtest5 ~]# which mysql
/usr/bin/which: no mysql in (/usr/lib64/qt-3.3/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin)
[root@dbtest5 ~]# whereis mysql
mysql:
[root@dbtest5 ~]# find / -name mysql
/var/lib/mysql
/var/lib/mysql/mysql
[root@dbtest5 ~]# rm -rf /var/lib/mysql
[root@dbtest5 ~]# rm -rf /var/lib/mysql/mysql

6.删除MySQL用户及组
如果存在MySQL相关用户和组信息,则进行删除:
[root@dbtest5 ~]# more /etc/passwd | grep mysql
mysql:x:101:501::/home/mysql:/bin/bash
[root@dbtest5 ~]# more /etc/shadow | grep mysql
mysql:!!:16496::::::
[root@dbtest5 ~]# more /etc/group | grep mysql
mysql:x:501:
[root@dbtest5 ~]# userdel mysql
[root@dbtest5 ~]# groupdel mysql
groupdel: group mysql does not exist

发表评论

电子邮件地址不会被公开。

您可以使用这些HTML标签和属性: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>