Home  >  Article  >  Backend Development  >  php 链接 mysql 数据库无法使用 localhost ,只能用 127.0.0.1

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

WBOY
WBOYOriginal
2016-06-06 20:38:001140browse

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

php不会从hosts里查吗?

回复内容:

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

php不会从hosts里查吗?

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

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

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

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

select user, host from mysql.user;

Statement:
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