Home > Database > Mysql Tutorial > Mac下PHP连接MySQL报错"No such file or directory"的解决办法

Mac下PHP连接MySQL报错"No such file or directory"的解决办法

WBOY
Release: 2016-06-07 17:24:08
Original
1249 people have browsed it

Mac下PHP连接MySQL报错"No such file or directory"的解决办法

首先做个简短的介绍。

[说明1]MAC下MYSQL的安装路径:/usr/local/mysql-5.5.28-osx10.6-x86

数据库的数据文件在该目录的data文件夹中;

命令文件在bin文件夹中。

[说明2]通过终端打开MYSQL命令行的方法:/usr/local/mysql-5.5.28-osx10.6-x86/bin/mysql

好下面说一下连接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(见说明2),执行命令 STATUS; 记下UNIX socket的值

Mac下PHP连接MYSQL报错"No such file or directory"的解决办法

4,如果2和3的值不一样,则打开php.ini(可以从phpinfo页面中找到php.ini的位置,默认是/private/etc/php.ini),将2中提到的三个配置项的值改成3的值。

Mac下PHP连接MYSQL报错"No such file or directory"的解决办法

(注意,一共修改三处,分别为:mysql.default_socket、mysqli.default_socket、pdo_mysql.default_socket)

5,重启apache

Mac下PHP连接MYSQL报错"No such file or directory"的解决办法

OK,到这里错误就排除了。

linux

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template