程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 數據庫知識 >> MYSQL數據庫 >> MySQL綜合教程 >> ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2),hy000mysql.sock

ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2),hy000mysql.sock

編輯:MySQL綜合教程

ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2),hy000mysql.sock


登錄服務器,使用root用戶連接mysql時出現錯誤提示:

$ bin/mysql -uroot -p
Enter password: 
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)

嘗試重啟mysql

$ ./mysql.server restart
Shutting down MySQL (Percona Server).......                [  OK  ]
rm: cannot remove `/var/lock/subsys/mysql': Permission denied
Starting MySQL (Percona Server)..                          [  OK  ]
[mysql@tongxtx mysql]$ bin/mysql -uroot -p
Enter password: 
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)

還是報同樣的錯。先看一下my.cnf

more my.cnf |grep sock
socket               = /opt/mysql/mysql.sock
socket              = /opt/mysql/mysql.sock

可以看到我的mysql已經聲明了mysql.sock的文件位置,而錯誤提示為/tmp/mysql.sock; 也就是說雖然我的mysql聲明了sock文件的位置,但是客戶端在連接的時候, linux系統總是去/tmp目錄下去找,找到了原因,就可以對症下藥了:

為mysql.sock創建鏈接文件:

$ ln -s /opt/mysql/mysql.sock /tmp/mysql.sock
然後再次連接mysql,成功連接

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved