MYSQL小白的FAQ系列—-4—-使用rpm包安装后,如何卸载干净mysql?

联系:QQ(5163721)

标题:MYSQL小白的FAQ系列—-4—-使用rpm包安装后,如何卸载干净mysql?

作者:Lunar©版权所有[文章允许转载,但必须以链接方式注明源地址,否则追究法律责任.]

首先卸载mysql组件:

[root@lunar ~]# rpm -aq|grep -i mysql
MySQL-server-advanced-5.6.21-1.rhel5      ---MySQL Server的rpm包
MySQL-test-advanced-5.6.21-1.rhel5        ---MySQL的test测试库
MySQL-client-advanced-5.6.21-1.rhel5       ----MySQL客户端
MySQL-embedded-advanced-5.6.21-1.rhel5     -----MySQL嵌入式开发包
MySQL-devel-advanced-5.6.21-1.rhel5        ---MySQL开发依赖包
MySQL-shared-advanced-5.6.21-1.rhel5
MySQL-shared-compat-advanced-5.6.21-1.rhel5
[root@lunar ~]# rpm -e MySQL*
error: package MySQL* is not installed
[root@lunar ~]# rpm -e MySQL-server-advanced-5.6.21-1.rhel5
[root@lunar ~]# rpm -e MySQL-test-advanced-5.6.21-1.rhel5
[root@lunar ~]# rpm -e MySQL-client-advanced-5.6.21-1.rhel5
[root@lunar ~]# rpm -e MySQL-embedded-advanced-5.6.21-1.rhel5
[root@lunar ~]# rpm -e MySQL-devel-advanced-5.6.21-1.rhel5
[root@lunar ~]# rpm -e MySQL-shared-advanced-5.6.21-1.rhel5
[root@lunar ~]# rpm -e MySQL-shared-compat-advanced-5.6.21-1.rhel5
[root@lunar ~]# rpm -qa|grep -i mysql
[root@lunar ~]# 

如果删除不掉,可以使用–nodeps参数,即防止互相依赖不能删除的情况
例如:rpm -e –nodeps MySQL-server-advanced-5.6.21-1.rhel5

然后清理mysql的配置文件,一般在/etc或者/usr下面:

[root@lunar ~]# ll /etc|grep my
[root@lunar ~]# ll /var|grep my
[root@lunar ~]# ll /usr|grep my
-rw-r--r--   1 root root   943 Aug  3 13:53 my.cnf
[root@lunar ~]# mv /usr/my.cnf /usr/my.cnf.bak
[root@lunar ~]# 

最后清理mysql的数据库目录:

[root@lunar ~]# cd /var/lib
[root@lunar lib]# ll mysql
total 110764
-rw-rw---- 1 mysql mysql       56 Aug  3 14:29 auto.cnf
-rw-rw---- 1 mysql mysql 12582912 Aug  3 15:45 ibdata1
-rw-rw---- 1 mysql mysql 50331648 Aug  3 15:45 ib_logfile0
-rw-rw---- 1 mysql mysql 50331648 Aug  3 13:53 ib_logfile1
drwx------ 2 mysql mysql     4096 Aug  3 15:14 lunardb
-rw-r----- 1 mysql root     17522 Aug  3 15:45 lunar.err
drwx--x--x 2 mysql mysql     4096 Aug  3 13:53 mysql
-rw-rw-r-- 1 mysql mysql       85 Aug  3 14:40 payload.c
drwx------ 2 mysql mysql     4096 Aug  3 13:53 performance_schema
-rw-r--r-- 1 root  root       115 Aug  3 13:53 RPM_UPGRADE_HISTORY
-rw-r--r-- 1 mysql mysql      115 Aug  3 13:53 RPM_UPGRADE_MARKER-LAST
drwxr-xr-x 2 mysql mysql     4096 Aug  3 13:53 test
[root@lunar lib]# rm -rf /var/lib/mysql
[root@lunar lib]# 

清理其他配置文件(字符集和一些配置脚本):

[root@lunar mysql]# cd /usr/share/mysql
[root@lunar mysql]# ls
binary-configure  dictionary.txt   fill_help_tables.sql  innodb_memcached_config.sql  my-default.cnf               mysql_system_tables_data.sql  polish      serbian
bulgarian         dutch            french                italian                      mysqld_multi.server          mysql_system_tables.sql       portuguese  slovak
charsets          english          german                japanese                     mysql-log-rotate             mysql_test_data_timezone.sql  romanian    spanish
czech             errmsg-utf8.txt  greek                 korean                       mysql_security_commands.sql  norwegian                     russian     swedish
danish            estonian         hungarian             magic                        mysql.server                 norwegian-ny                  SELinux     ukrainian
[root@lunar mysql]# 

清理一下mysql的相关命令:

[root@lunar mysql]# ll /usr/bin|grep -i mysql
-rwxr-xr-x 1 root root         930 Sep 11  2014 msql2mysql
-rwxr-xr-x 1 root root     8299942 Sep 11  2014 mysql
-rwxr-xr-x 1 root root      111136 Sep 11  2014 mysqlaccess
-rw-r--r-- 1 root root        1702 Sep 11  2014 mysqlaccess.conf
-rwxr-xr-x 1 root root     7320299 Sep 11  2014 mysqladmin
-rwxr-xr-x 1 root root     8121731 Sep 11  2014 mysqlbinlog
-rwxr-xr-x 1 root root       11019 Sep 11  2014 mysqlbug
-rwxr-xr-x 1 root root     7300011 Sep 11  2014 mysqlcheck
-rwxr-xr-x 1 root root     8366903 Sep 11  2014 mysql_client_test
-rwxr-xr-x 1 root root    73110360 Sep 11  2014 mysql_client_test_embedded
-rwxr-xr-x 1 root root        6223 Sep 11  2014 mysql_config
-rwxr-xr-x 1 root root     5843349 Sep 11  2014 mysql_config_editor
-rwxr-xr-x 1 root root        3714 Sep 11  2014 mysql_convert_table_format
-rwxr-xr-x 1 root root       25749 Sep 11  2014 mysqld_multi
-rwxr-xr-x 1 root root       24691 Sep 11  2014 mysqld_safe
-rwxr-xr-x 1 root root     7536459 Sep 11  2014 mysqldump
-rwxr-xr-x 1 root root        6817 Sep 11  2014 mysqldumpslow
-rwxr-xr-x 1 root root    72920866 Sep 11  2014 mysql_embedded
-rwxr-xr-x 1 root root        2789 Sep 11  2014 mysql_find_rows
-rwxr-xr-x 1 root root         726 Sep 11  2014 mysql_fix_extensions
-rwxr-xr-x 1 root root       34331 Sep 11  2014 mysqlhotcopy
-rwxr-xr-x 1 root root     7310676 Sep 11  2014 mysqlimport
-rwxr-xr-x 1 root root       34014 Sep 11  2014 mysql_install_db
-rwxr-xr-x 1 root root     5775748 Sep 11  2014 mysql_plugin
-rwxr-xr-x 1 root root        9523 Sep 11  2014 mysql_secure_installation
-rwxr-xr-x 1 root root     7290946 Sep 11  2014 mysqlshow
-rwxr-xr-x 1 root root     7367269 Sep 11  2014 mysqlslap
-rwxr-xr-x 1 root root     7957948 Sep 11  2014 mysqltest
-rwxr-xr-x 1 root root    72420298 Sep 11  2014 mysqltest_embedded
-rwxr-xr-x 1 root root     4384753 Sep 11  2014 mysql_tzinfo_to_sql
-rwxr-xr-x 1 root root     5928802 Sep 11  2014 mysql_upgrade
-rwxr-xr-x 1 root root     5725249 Sep 11  2014 mysql_waitpid
-rwxr-xr-x 1 root root        3356 Sep 11  2014 mysql_zap
[root@lunar mysql]# 

清理mysql的启动脚本:

[root@lunar mysql]# ll /etc/rc.d/init.d/mysql*
-rwxr-xr-x 1 root root 10815 Sep 11  2014 /etc/rc.d/init.d/mysql
[root@lunar mysql]# 

清理其他mysql的安装文件和目录:
[root@lunar mysql]# whereis mysql
mysql: /usr/bin/mysql /usr/include/mysql /usr/share/mysql /usr/share/man/man1/mysql.1.gz
[root@lunar mysql]# 

再看一下系统中是否还有mysql的进程,如果有kill掉:

[root@lunar lib]# ps -ef|grep -i mysql
root      3733  3227  0 14:29 pts/0    00:00:00 mysql -h localhost -uroot -p
root      4706  3812  0 15:50 pts/4    00:00:00 grep -i mysql
[root@lunar lib]# ps -ef|grep 3733
root      3733  3227  0 14:29 pts/0    00:00:00 mysql -h localhost -uroot -p
root      4712  3812  0 15:50 pts/4    00:00:00 grep 3733
[root@lunar lib]# ps -ef|grep 3227
root      3227  2049  0 14:03 pts/0    00:00:00 -bash
root      3733  3227  0 14:29 pts/0    00:00:00 mysql -h localhost -uroot -p
root      4714  3812  0 15:50 pts/4    00:00:00 grep 3227
[root@lunar lib]# kill -9 3733
[root@lunar lib]# ps -ef|grep -i mysql
root      4716  3812  0 15:51 pts/4    00:00:00 grep -i mysql
[root@lunar lib]# 

我使用root的安装的,因此在/root下还有两个隐藏的mysql文件需要清理:
一个是记录了mysql的执行历史的文件:.mysql_history
一个是系统安装时生成的root的临时口令文件:.mysql_secret

他这两个文件直接删除就可以了,好了,现在系统就干净了。

还有一种简单的方法,直接查看系统当前所有的目录,然后对应的直接删除,在清理mysql进程就好了;
查看系统当前的各种目录:

mysql> show variables like '%dir%';
+-----------------------------------------+----------------------------+
| Variable_name                           | Value                      |
+-----------------------------------------+----------------------------+
| basedir                                 | /usr                       |
| binlog_direct_non_transactional_updates | OFF                        |
| character_sets_dir                      | /usr/share/mysql/charsets/ |
| datadir                                 | /var/lib/mysql/            |
| ignore_db_dirs                          |                            |
| innodb_data_home_dir                    |                            |
| innodb_log_group_home_dir               | ./                         |
| innodb_max_dirty_pages_pct              | 75                         |
| innodb_max_dirty_pages_pct_lwm          | 0                          |
| innodb_undo_directory                   | .                          |
| lc_messages_dir                         | /usr/share/mysql/          |
| plugin_dir                              | /usr/lib64/mysql/plugin/   |
| slave_load_tmpdir                       | /tmp                       |
| tmpdir                                  | /tmp                       |
+-----------------------------------------+----------------------------+
14 rows in set (0.00 sec)

mysql> 
此条目发表在 FAQ 分类目录,贴了 , 标签。将固定链接加入收藏夹。

发表评论

电子邮件地址不会被公开。 必填项已用 * 标注