我正在尝试从 Windows/IIS 7.5 上的 PHP (WordPress) 连接到 MySQL,结果是这样的:
define('DB_HOST', 'DevPC'); // -> works
define('DB_HOST', 'localhost'); // -> connection error
奇怪的是,在另一台机器上(Windows Server + IIS 7.5),localhost
工作正常。是什么原因造成的?一些 PHP 设置? MySQL 设置?
最佳答案
On Unix, MySQL programs treat the host name
localhost
specially, in a way that is likely different from what you expect compared to other network-based programs. For connections to localhost, MySQL programs attempt to connect to the local server by using a Unix socket file. This occurs even if a--port
or-P
option is given to specify a port number.
使用 127.0.0.1
而不是 localhost
。
关于php - 为什么 "localhost"不能用作 MySQL 主机,而 "MyPCName"可以?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9650954/