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

1.首先登录mysql命令行,查看unix socket所在目录。

mysql> STATUS

--------------

/usr/local/mysql/bin/mysql  Ver 14.14 Distrib 5.7.15, for osx10.11 (x86_64) using  EditLine wrapper


Connection id: 2

Current database: todo_list

Current user: root@localhost

SSL: Not in use

Current pager: stdout

Using outfile: ''

Using delimiter: ;

Server version: 5.7.15 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: 10 hours 53 min 25 sec


2. 根据phpinfo()查看 php.ini的目录和找到mysql.default_socket、mysqli.default_socket、pdo_mysql.default_socket的所在目录。mac下php.ini默认的目录是/private/etc/php.ini.

    若mysql.default_socket、mysqli.default_socket、pdo_mysql.default_socket的值不是步骤1中的/tmp/mysql.sock,则修改php.ini中的mysql.default_socket、mysqli.default_socket、pdo_mysql.default_socket值为 /tmp/mysql.sock

/private/etc/php.ini不存在,则复制一个

cp /private/etc/php.ini.default /private/etc/php.ini


3. 重启apache

sudo apachectl restart



reference: http://www.cnblogs.com/whlives/p/4495106.html


你可能感兴趣的:(mac 连接mysql提示 Warning: mysqli::real_connect(): (HY000/2002): No such file or directory)