linux下 mysql完全卸載

來源:互聯網
上載者:User

標籤:如何   list   complete   bsp   方法   blank   服務   com   完全卸載   

如何在Linux下卸載MySQL資料庫呢? 下面總結、整理了一下Linux平台下卸載MySQL的方法。 MySQL的安裝主要有三種方式:二進位包安裝(Using Generic Binaries)、RPM包安裝、源碼安裝。對應不同的安裝方式,卸載的步驟有些不同。文章中如有不足或不對的地方,敬請指出或補充!

 

RPM包安裝方式的MySQL卸載

 

1: 檢查是否安裝了MySQL組件。

[[email protected] init.d]# rpm -qa | grep -i mysql
 
MySQL-devel-5.6.23-1.linux_glibc2.5
 
MySQL-client-5.6.23-1.linux_glibc2.5
 
MySQL-server-5.6.23-1.linux_glibc2.5
 

如上所示,說明安裝了MySQL 5.6.23這個版本的client、server、devel三個組件。

 

2: 卸載前關閉MySQL服務

 

2.1 方法1

[[email protected] init.d]# service mysql status
 MySQL running (25673)[  OK  ]
[[email protected] init.d]# service mysql stop
 Shutting down MySQL..[  OK  ]
[[email protected] init.d]# service mysql status
 MySQL is not running[FAILED]

 

2.2 方法2

[[email protected] init.d]# ./mysql status
 MySQL running (26215)[  OK  ]
[[email protected] init.d]# ./mysql stop
 Shutting down MySQL..[  OK  ]
[[email protected] init.d]# ./mysql status
 MySQL is not running[FAILED]
[[email protected] init.d]# 

[[email protected] init.d]# chkconfig --list | grep -i mysql
 
mysql 0:off 1:off 2:on 3:on 4:on 5:on 6:off
 
[[email protected] init.d]# 
 

 

3. 收集MySQL對應的檔案夾資訊

[[email protected] init.d]# whereis mysql

mysql: /usr/bin/mysql /usr/include/mysql /usr/share/mysql /usr/share/man/man1/mysql.1.gz

最好實用find命令查看MySQL資料庫相關的檔案,方便後面徹底刪除MySQL。

[[email protected] init.d]# find / -name mysql
/etc/rc.d/init.d/mysql
/etc/logrotate.d/mysql
/var/lock/subsys/mysql
/var/lib/mysql
/var/lib/mysql/mysql
/usr/include/mysql
/usr/include/mysql/mysql
/usr/bin/mysql
/usr/share/mysql
/usr/lib64/mysql

 

4: 卸載刪除MySQL各類組件

[[email protected] init.d]# 
[[email protected] init.d]# rpm -ev MySQL-devel-5.6.23-1.linux_glibc2.5
[[email protected] init.d]# rpm -ev MySQL-server-5.6.23-1.linux_glibc2.5
You have new mail in /var/spool/mail/root
[[email protected] init.d]# rpm -ev MySQL-client-5.6.23-1.linux_glibc2.5
[[email protected] init.d]#

 

5:刪除MySQL對應的檔案夾

 

檢查各個MySQL檔案夾是否清理刪除乾淨。

[[email protected] init.d]# whereis mysql
mysql:
[[email protected] init.d]# find / -name mysql
/var/lib/mysql
/var/lib/mysql/mysql
/usr/lib64/mysql
[[email protected] init.d]# rm -rf /var/lib/mysql
[[email protected] init.d]# rm -rf /var/lib/mysql/mysql
[[email protected] init.d]# rm -rf /usr/lib64/mysql
[[email protected] init.d]# 

6:刪除mysql使用者及使用者組

如果有必要,刪除mysql使用者以及mysql使用者組。

[[email protected] ~]# more /etc/passwd | grep mysql
mysql:x:101:501::/home/mysql:/bin/bash
[[email protected] ~]# more /etc/shadow | grep mysql
mysql:!!:16496::::::
[[email protected] ~]# more /etc/group | grep mysql
mysql:x:501:
[[email protected] ~]# userdel mysql
[[email protected] ~]# groupdel mysql
groupdel: group mysql does not exist
[[email protected] ~]# 

 

7:確認MySQL是否卸載刪除

[[email protected] init.d]# rpm -qa | grep -i mysql

 

二進位包/源碼安裝方式的MySQL卸載

如果是採用二進位包安裝的MySQL,那麼你用下面命令是找不到任何MySQL組件的。所以如果你不知道MySQL的安裝方式,千萬不要用下面命令來判別是否安裝了MySQL

[[email protected] init.d]# rpm -qa | grep -i mysql

 

1: 檢查MySQL服務並關閉服務進程

 

首先通過進程查看是否有MySQL的服務的狀態, 如下所示,MySQL服務是啟動的。

[[email protected] init.d]# ps -ef | grep mysql
root      4752  4302  0 22:55 pts/1    00:00:00 more /etc/init.d/mysql.server
root      7176     1  0 23:23 pts/1    00:00:00 /bin/sh /usr/local/mysql/bin/mysqld_safe --datadir=/usr/local/mysql/data --pid-file=/usr/local/mysql/data/DB-Server.localdomain.pid
mysql     7269  7176 15 23:23 pts/1    00:00:01 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=/usr/local/mysql/data/DB-Server.localdomain.err --pid-file=/usr/local/mysql/data/DB-Server.localdomain.pid
root      7321  4302  0 23:23 pts/1    00:00:00 grep mysql
[[email protected] init.d]# /etc/init.d/mysql.server status
MySQL running (7269)[  OK  ]
[[email protected] init.d]# /etc/init.d/mysql.server stop
Shutting down MySQL..[  OK  ]
[[email protected] init.d]# /etc/init.d/mysql.server status
MySQL is not running[FAILED]
[[email protected] init.d]# 

 

2: 尋找MySQL的安裝目錄並徹底刪除

[[email protected] init.d]# whereis mysql
 
mysql: /usr/local/mysql
 
[[email protected] init.d]# find / -name mysql
 
/var/spool/mail/mysql
 
/usr/local/mysql-5.7.5-m15-linux-glibc2.5-x86_64/include/mysql
 
/usr/local/mysql-5.7.5-m15-linux-glibc2.5-x86_64/bin/mysql
 
/usr/local/mysql-5.7.5-m15-linux-glibc2.5-x86_64/data/mysql
 
/usr/local/mysql
 

[[email protected] init.d]# rm -rf /usr/local/mysql-5.7.5-m15-linux-glibc2.5-x86_64/
 
[[email protected] init.d]# rm -rf /usr/local/
 
[[email protected] init.d]# rm -rf /var/spool/mail/mysql
 
[[email protected] init.d]# 
 

 

3: 刪除一些設定檔

設定檔一般有/etc/my.cnf 或/etc/init.d/mysql.server,視具體安裝配置情況而定。

 

4:刪除MySQL使用者以及使用者組

[[email protected] ~]# id mysql
 
uid=101(mysql) gid=501(mysql) groups=501(mysql) context=root:system_r:unconfined_t:SystemLow-SystemHigh
 
[[email protected] ~]# userdel mysql
 

 

參考資料

http://blog.itblood.com/completely-uninstall-the-mysql-under-linux-graphic-tutorials.html

 

linux下 mysql完全卸載

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.