当前位置: 代码迷 >> Ruby/Rails >> ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock'
  详细解决方案

ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock'

热度:183   发布时间:2016-04-29 02:16:49.0
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock'

今天mysql不知道犯啥病,root登录的时候一直报这个错误。

在国内网站找了找,没什么合适的 答案,在stackoverflow和ubuntu的一个社区上找到了答案,搞定了,但是没太看懂,记录一下,以后再翻。


That said, Here is what I did/ found out:
1. You don't have to change the tmp directory in the my.cnf file. Even adding a second directory, changing from tempdir =/tmp to =/tmp:/newdir crashed mysql. In 10.04 using MySQL 5.1 you used to have to add the second path other wise you got an error something like can't write temp file.... Of course did change the datadir to /MyDisk/myNewDir

2. Used the wrong permission flags on my file copy from the command line. Should use cp -R -p /var/lib/mysql /MyDisk/myNewDir. Not sure if that really mattered as trashed old dir and started over with the flags as stated so did not test with old permissions. This did work.

3. Added /MyDisk/myNewDir/ r, and /MyDisk/myNewDir/* rwk, to the bottom of etc/apparmor.d/usr.sbin.mysqld file. Also changed the var/lib/mysql entries in apparmor as above

4. Left in the var/run... file as created above. Also not sure if that matters but already behind in getting the server updated so not really caring past having it working properly. 

sudo service mysql stop
sudo /etc/init.d/apparmor reload
sudo service mysql start 


and this worked.


没看太懂,也没时间翻译了,先欠着吧。。红字是解决方法。

附个链接ubuntu forum

  相关解决方案