Home >php教程 >php手册 >mysql_connect提示"No such file or directory"错误"

mysql_connect提示"No such file or directory"错误"

WBOY
WBOYOriginal
2016-06-13 09:56:551817browse

有些朋友在使用mysql连接时会出现No such file or directory错误提示,下面我来总结解决办法。

连接代码

 代码如下 复制代码

$this->linkid = @mysql_pconnect($host, $user, $password) or die(mysql_error());


Make a phpinfo() page.  Look for ‘mysql.default_socket‘, ‘mysqli.default_socket‘, and

‘pdo_mysql.default_socket‘.  Remember their value; this is where PHP is trying to connect to MySQL.

解决办法

1.首先确定是mysql_connect()和mysql_pconnect()的问题,故障现象就是函数返回空,而mysql_error()返回“No

such file or directory”。
2.写个phpinfo页面,找到mysql.default_socket、mysqli.default_socket、pdo_mysql.default_socket。
3.启动mysql,执行命令 STATUS; 记下UNIX socket的值。
4.如果2和3的值不一样,则打开php.ini(可以从phpinfo页面中找到php.ini的位置,默认是/private/etc/php.ini)

,将2中提到的三个配置项的值改成3的值。
5.重启apache。

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