异常ERROR 2002 (HY000): Can’t connect to local MySQL server through socket ‘/tmp/mysql.sock

Posted N!CE波

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了异常ERROR 2002 (HY000): Can’t connect to local MySQL server through socket ‘/tmp/mysql.sock相关的知识,希望对你有一定的参考价值。

当我们只行 mysql -uroot -p时,出现如下错误:

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

那可能是因为你当前服务的mysql服务没有启动起来,试着重启服务后再试一试可能就好了;
或着:find / -name mysql.sock若找到文件,做一个软连接到/tmp目录下也可以

 

正确解:请通过下面的方式连接mysql,使用的使tcp/ip协议。而上面是通过一个Unix域套接字文件进行,一般是/tmp/mysql.sock。如果套接字文件被删除了,本地客户就不能连接。

mysql -uroot -h 127.0.0.1 -p

 

以上是关于异常ERROR 2002 (HY000): Can’t connect to local MySQL server through socket ‘/tmp/mysql.sock的主要内容,如果未能解决你的问题,请参考以下文章

Can't access Phpmyadmin in ubuntu error mysqli_real_connect(): (HY000/2002)

ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' 。安装后出错

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

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

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 '/tmp/mysql.sock' (2) when I