二次安裝 MySQL 時,殘留的配置文件、數據目錄、運行進程往往導致安裝失敗或服務啟動異常。本文總結了生產環境驗證過的徹底清理方案。
# 查詢已安裝包
rpm -qa | grep mysql
# 按順序卸載(客戶端優先)
rpm -e MySQL-client-community-5.1.40-0.rhel5
rpm -e MySQL-server-community-5.1.40-0.rhel5
RPM 卸載不會刪除以下關鍵路徑,需手動清理:
/var/lib/mysql — 數據目錄(含表空間、日志)/etc/my.cnf — 主配置文件/usr/local/mysql — 源碼安裝的默認目錄rm -rf /var/lib/mysql /etc/my.cnf /usr/local/mysql
ps -ef | grep mysql
# 典型殘留進程:
# root 4885 1 0 10:43 ? 00:00:00 /bin/sh bin/mysqld_safe --user=mysql
# mysql 4984 4885 0 10:43 ? 00:00:00 /usr/local/mysql/bin/mysqld ...
kill -9 4885 4984 # 逐個殺掉所有 mysql 相關進程
Starting MySQL..Manager of pid-file quit without updating file.[失敗]
Giving mysqld 2 seconds to start.
此錯誤 90% 由未清理的舊進程或數據目錄權限問題引起,執行上述三步即可解決。