1.找到/private/etc/php.ini文件,并打开并查看文件
.....
pdo_mysql.default_socket=
.....
mysql.default_socket =
.....
mysqli.default_socket =
.....
你会看到里面的这三个值内容为空或者有值。
2.打开终端运行mysql,输入如下命令
mysql> status
1
输出如下内容
--------------
/usr/local/mysql/bin/mysql Ver 14.14 Distrib 5.7.10, for osx10.9 (x86_64) using EditLine wrapper
Connection id: 16
Current database:
Current user: root@localhost
SSL: Not in use
Current pager: less
Using outfile: ''
Using delimiter: ;
Server version: 5.7.10 MySQL Community Server (GPL)
Protocol version: 10
Connection: Localhost via UNIX socket
Server characterset: latin1
Db characterset: latin1
Client characterset: utf8
Conn. characterset: utf8
UNIX socket: /tmp/mysql.sock
Uptime: 23 hours 41 min 51 sec
Threads: 11 Questions: 199 Slow queries: 0 Opens: 157 Flush tables: 1 Open tables: 150 Queries per second avg: 0.002
--------------
复制下 UNIX socket:后面的值 /tmp/mysql.sock
然后修改第1步中找到的三个值为/tmp/mysql.sock 如下情况
.....
pdo_mysql.default_socket=/tmp/mysql.sock
.....
mysql.default_socket =/tmp/mysql.sock
.....
mysqli.default_socket =/tmp/mysql.sock
.....
然后打开终端运行如下命令,重启apache服务器
sudo apachectl restart
1
然后重新调试php代码就可以解决问题了!