Unable to connect to MySQL: connection("Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)")
如果確認(rèn)mysql服務(wù)正常運行,還提示文章標(biāo)題的此錯誤骇塘,那就是“/etc/my.cnf”配置文件的問題了瞒渠。解決辦法是修改“/etc/my.cnf”配置文件宿百,在配置文件中添加“[client]”選項和“[mysql]”選項,并使用這兩個選項下的“socket”參數(shù)值愿险,與“[mysqld]”選項下的“socket”參數(shù)值瘟滨,指向的socket文件路徑完全一致。如下:
[mysqld]
datadir=/storage/db/mysql
socket=/storage/db/mysql/mysql.sock
...省略n行(愛E族)...
[client]
default-character-set=utf8
socket=/storage/db/mysql/mysql.sock
[mysql]
default-character-set=utf8
socket=/storage/db/mysql/mysql.sock