当前位置:Gxlcms >
mysql >
Can’tconnecttolocalMySQLserverthroughsocket解决办法_MySQL
Can’tconnecttolocalMySQLserverthroughsocket解决办法_MySQL
时间:2021-07-01 10:21:17
帮助过:33人阅读
故障描述:
启动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