ERROR 2002 (HY000): Can’t connect to local MySQL server through socket 解决办法

故障描述:

启动mysql 报错:
ERROR 2002 (HY000): Can’t connect to local MySQL server through socket ‘/var/lib/mysql/mysql.sock’ (2)

1.先查看mysql启动状态

/etc/rc.d/init.d/mysqld status

2.mysql.sock位置查找与验证?

find / -name mysql.sock

/Data/mydata/mysql.sock
验证目录是否正确

mysql -u root -p -S /Data/mydata/mysql.sock

备注:-S参数socket file文件验证

3.验证mysql.sock文件权限和用户是否正确?
如果是权限问题,则先改变权限

chown -R mysql:mysql /Data/mydata/mysql.sock

[root@localhost ~]# /etc/init.d/mysqld start
启动 MySQL: [ OK]

4.永久解决

修改/etc/my.cnf

添加以下内容到/etc/my.conf:
[client]
socket = /Data/mydata/mysql.sock
[mysqld]

socket = /Data/mydata/mysql.sock

你可能感兴趣的:(ERROR 2002 (HY000): Can’t connect to local MySQL server through socket 解决办法)