1. 程式人生 > >MYSQL啟動異常:Can 't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock '(2) "

MYSQL啟動異常:Can 't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock '(2) "

一次異常關機之後,再次啟動mysql服務,報出異常Can 't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock '(2) "。
之前在伺服器上遇到過兩次這種情況,一次是通過在另一個目錄搞了一個連結過去,這個解決方案網上很多,一搜都是;另一次是因為伺服器空間不足,刪除一些應用之後mysql成功啟動。但是這次在本機中這兩種方法都沒能解決問題,開啟錯誤日誌/var/log/mysql/error.log看到如下內容:
140417  7:30:38 [Note] Server hostname (bind-address): '10.213.214.138'; port: 3306
140417  7:30:38 [Note]   - '10.213.214.138' resolves to '10.213.214.138';
140417  7:30:38 [Note] Server socket created on IP: '10.213.214.138'.
140417  7:30:38 [ERROR] Can't start server: Bind on TCP/IP port: Cannot assign requested address
140417  7:30:38 [ERROR] Do you already have another mysqld server running on port: 3306 ?g
140417  7:30:38 [ERROR] Aborting

140417  7:30:38  InnoDB: Starting shutdown...
140417  7:30:39  InnoDB: Shutdown completed; log sequence number 5026365941

想起來之前修改過mysql的配置檔案,新增過bind-address為了讓遠端機訪問,現在日誌顯示連線不上該遠端機ip了

[mysqld]
user    = mysql
pid-file  = /var/run/mysqld/mysqld.pid
socket    = /var/run/mysqld/mysqld.sock
port      = 3306
basedir   = /usr
datadir   = /var/lib/mysql
tmpdir    = /tmp
max_connections = 151
skip-external-locking

bind-address        = 127.0.0.1
bind-address        = 10.213.214.138

將bind-address        = 10.213.214.138註釋或者刪掉就可以了。。。
重新啟動mysql服務,一切正常。。。所以說看日誌檔案很重要