錯誤現象
[root@itcast02 itcast]# /etc/init.d/mysql restart
ERROR! MySQL server PID file could not be found!
Starting MySQL................ ERROR! The server quit without updating PID file (/var/lib/mysql/itcast02.pid).
[root@itcast02 itcast]# mysql -u root -p
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)
排查步驟
- 檢查數據目錄權限:
chown -R mysql:mysql /var/lib/mysql。
- 重新啟動:
/etc/init.d/mysql restart。
修復結果
[root@itcast02 itcast]# chown -R mysql:mysql /var/lib/mysql
[root@itcast02 itcast]# /etc/init.d/mysql restart
ERROR! MySQL server PID file could not be found!
Starting MySQL...... SUCCESS!
[root@itcast02 itcast]# mysql -u root -p
Enter password:
Welcome to the MySQL monitor...
根因分析
- 數據目錄文件所有者非 mysql 用戶,導致 mysqld 無法寫入 PID 文件、創建 Socket 文件。
- 權限修正後,服務正常啟動,Socket 自動生成,客戶端連接恢復。
通用檢查清單
datadir 權限:chown -R mysql:mysql、chmod 750。
pid-file 目錄可寫。
socket 目錄可寫(通常同 datadir 或 /tmp)。
error.log 可寫,便於後續排查。
- SELinux/AppArmor 是否阻擋 mysqld 寫入。