首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式碼之家 >> 數據庫知識 >  >> MySQL 資料庫 >> MySQL 綜合教學

MySQL 啟動報錯 PID 文件丟失、Socket 連接失敗排查與修復

     編輯:MySQL 綜合教學

錯誤現象


[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)

排查步驟

  1. 檢查數據目錄權限:chown -R mysql:mysql /var/lib/mysql。
  2. 重新啟動:/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 寫入。
  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式碼之家 All Rights Reserved