Linux MySQL:解决Can 't connect to local MySQL server through socket '/tmp/mysql.sock '(2) ";

已经遇到两次了,第一次改好后今天再次出现,记录一下。


Linux MySQL:解决Can 't connect to local MySQL server through socket '/tmp/mysql.sock '(2)
Can 't connect to local MySQL server through socket '/tmp/mysql.sock '(2) ";

问题是:没有找到mysql.sock
先了解下mysql.sock:
连接localhost通常通过一个Unix域套接字文件进行,一般是/tmp/mysql.sock。如果套接字文件被删除了,本地客户就不能连接。这可能发生在你的系统运行一个cron任务删除了/tmp下的临时文件。

运行: find / -name mysql.sock   #找到mysqld.sock路径

更改my.cnf:目录为/etc/my.cnf

vi /etc/my.cnf
Linux MySQL:解决Can 't connect to local MySQL server through socket '/tmp/mysql.sock '(2)
my.cnf

重启MySQL

service mysql restart
Linux MySQL:解决Can 't connect to local MySQL server through socket '/tmp/mysql.sock '(2)
重启

再进入my.cnf 把注释切换(把find的路径注释,把原路径取消注释)


Linux MySQL:解决Can 't connect to local MySQL server through socket '/tmp/mysql.sock '(2)
image.png

重启MySQL,登录


Linux MySQL:解决Can 't connect to local MySQL server through socket '/tmp/mysql.sock '(2)
image.png

你可能感兴趣的:(Linux MySQL:解决Can 't connect to local MySQL server through socket '/tmp/mysql.sock '(2) ";)