mysql.sock 链接不上?

某测试服务器好久没管了,晚上测试刚好在这台机器上遇到个mysql常见问题,于是用官网里面的的一段代码来做测试:

$link = mysql_connect('localhost', 'root', '');
if (!$link) {
    die('Could not connect: ' . mysql_error());
}
echo 'Connected successfully';
mysql_close($link);

echo "\n\n";

存成 db_test.php

结果是:

#php db_test.php

PHP Warning:  mysql_connect(): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2) in /wwroot/test/cmd/db_test.php on line 1
好家伙,命令登录mysql服务命名是可以访问的呢。。。看来是sock文件有木有:
# find / -name "mysql.sock"
/tmp/mysql.sock
结果只发现这个玩意儿,好嘛,简单点搞,给建一个软连接
#ln -s /tmp/mysql.sock /var/lib/mysql/mysql.sock

然后再次运行下PHP的测试代码:

# php db_test.php 

Connected successfully

至此,问题解决,欧了~

你可能感兴趣的:(mysql.sock 链接不上?)