无法连接:无法通过socket' /var/lib/mysql/mysql.sock&#39连接到本地MySQL服务器; (2)

时间:2012-05-23 01:46:19

标签: php mysql centos

当我通过php脚本连接我的数据库时,它显示

Could not connect: Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)

用户名和密码是对的。

某些my.cnf

[client]
#password       = your_password
port            = 3306
socket          = /data/mysql/mysql.sock

# Here follows entries for some specific programs

# The MySQL server
[mysqld]
port            = 3306
socket          = /data/mysql/mysql.sock
skip-external-locking

ps:我将它更改为socket = /var/lib/mysql/mysql.sock php脚本仍然显示“/var/lib/mysql/mysql.sock”?然后运行

  mysqladmin -u root -p status

显示

mysqladmin: connect to server at 'localhost' failed
error: 'Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)'
Check that mysqld is running and that the socket: '/var/lib/mysql/mysql.sock' exists!




service mysqld restart


mysqld: unrecognized service

1 个答案:

答案 0 :(得分:1)

问:你的my.conf仍然说“/var/lib/mysql/mysql.sock”吗?

问:目录“/ var / lib / mysql”是否存在?

问:你的mysql用户(或者更好的mysql组)是否有写入权限?

如果是这样,请尝试重新启动mysql,看看会发生什么。

附录:

要尝试的另一件事是创建一个mysql.sock并显式赋予它的权限:

cd /var/lib
mkdir mysql
touch mysql/mysql.sock
chown -R mysql:mysql mysql