Home >Database >Mysql Tutorial >Can’tconnecttolocalMySQLserverthroughsocket解决办法_MySQL

Can’tconnecttolocalMySQLserverthroughsocket解决办法_MySQL

WBOY
WBOYOriginal
2016-06-01 13:00:532854browse

故障描述:
启动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
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn