在連接mysql的時,經常會出現以下錯誤提示:
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock'
出現此錯誤提示的原因一般有倆個:
一、mysql服務為啟動
該sock文件是mysql啟動的時候創建的,弱服務關閉,該文件消失。
判斷mysql是否正常啟動有倆個方法:
方法一:
[root@localhost ~]# ps -ef | grep mysql 101 17285 16922 0 Apr04 pts/1 00:36:51 /usr/bin/mysqld --basedir=/usr --datadir=/var/lib/mysql --plugin-dir=/usr/lib/mysql/plugin --user=mysql --log-output=none --pid-file=/var/lib/mysql/mysqld.pid --port=3306 --console root 25314 25296 0 22:50 pts/0 00:00:00 grep --color=auto mysql
方法二:
[root@localhost ~]# netstat -ntlp | grep 3306
二、socket文件路徑配置錯誤
該問題一般是由於修改mysql的配置文件my.conf導致,查找文件中socket參數,修改正確即可;
