mac 连接mysql提示 Warning: mysqli::real_connect(): (HY000/2002): No such file or directory - whlives - 博客园

mac 连接mysql的时候提示

Warning: mysqli::real_connect(): (HY000/2002): 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,到这里错误就排除了。


Original url: Access
Created at: 2018-10-23 22:44:04
Category: default
Tags: none

请先后发表评论
  • 最新评论
  • 总共1条评论
DeepMind

Rain酱

Fatal error: Uncaught PDOException: SQLSTATE[HY000] [2002] No such file or directory in /data/wwwroot/default/superdesk/framework/class/db.class.php:55 Stack trace: #0 /data/wwwroot/default/superdesk/framework/class/db.class.php(55): PDO->__construct('mysql:dbname=db...', 'root', 'fuckyou88816899...', Array) #1 /data/wwwroot/default/superdesk/framework/class/db.class.php(25): DB->connect('master') #2 /data/wwwroot/default/superdesk/framework/function/pdo.func.php(22): DB->__construct('master') #3 /data/wwwroot/default/superdesk/framework/function/pdo.func.php(36): pdo() #4 /data/wwwroot/default/superdesk/framework/function/cache.mysql.func.php(13): pdo_fetchcolumn('SELECT `value` ...', Array) #5 /data/wwwroot/default/superdesk/framework/function/cache.func.php(31): cache_read('setting') #6 /data/wwwroot/default/superdesk/framework/model/setting.mod.php(35): cache_load('setting') #7 /data/wwwroot/default/superdesk/framework/bootstrap.inc.php(126): setting_load() #8 /data/wwwroot/default/superdesk/index.php(6): require('/da in /data/wwwroot/default/superdesk/framework/class/db.class.php on line 55

2018-10-23 22:44:15 回复