php 链接 mysql 数据库无法使用 localhost ,只能用 127.0.0.1


mac 下 php 链接 mysql 数据库,设置 mysql 地址时无法使用 localhost ,只能用 127.0.0.1。

php不会从hosts里查吗?

mysql php

左眼看右手 9 years, 2 months ago

select user, host from mysql.user;

-风之旅人 answered 9 years, 2 months ago

请记住这一条:对于 mysql 来说,localhost和127.0.0.1并不等价。

呐,黑锅不要扣给php,明明是mysql的问题。

GiGi.us answered 9 years, 2 months ago

php.ini下有这样一个配置项:
mysql.default_socket =
试着改成对应的mysqld.sock文件,如:
mysql.default_socket = /var/run/mysqld/mysqld.sock

BCkong answered 9 years, 2 months ago

Linux下使用 localhost 默认是使用 sock 连接, 127.0.0.1 则是使用 tcp 来连接

Arsenal answered 9 years, 2 months ago

Your Answer