gpt4 book ai didi

php - 警告 : mysqli_connect(): (HY000/2002): No such file or directory

转载 作者:IT老高 更新时间:2023-10-28 23:43:33 27 4
gpt4 key购买 nike

我正在尝试在我的 Mac 上安装原版论坛,为此我刚刚从 MySQL 命令行创建了一个数据库和一个用户:

mysql> CREATE DATABASE vanilla;
Query OK, 1 row affected (0.00 sec)

mysql> create user 'vanilla_user3'@'localhost' IDENTIFIED BY 'vanilla_password';
Query OK, 0 rows affected (0.00 sec)

mysql> GRANT ALL PRIVILEGES ON * . * TO 'vanilla_user3'@'localhost';
Query OK, 0 rows affected (0.00 sec)

mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.00 sec)

所以我尝试使用以下代码进行连接:

$con=mysqli_connect("localhost","vanilla_user3","vanilla_password","vanilla");
if (mysqli_connect_errno($con)) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}

但不幸的是,我收到一条错误消息

Warning: mysqli_connect(): (HY000/2002): No such file or directory in /Users/kramer65/Sites/vanilla/info.php on line 3 Failed to connect to MySQL: No such file or directory

知道我哪里出错了吗?

最佳答案

好的,我刚刚找到了解决方案。问题原来是主机不应该是localhost,而是127.0.0.1。我一直以为localhost127.0.0.1是一样的,结果却不一样。

所以也许作为对 future 用户的提示,当有疑问时,请始终使用该 ip。

关于php - 警告 : mysqli_connect(): (HY000/2002): No such file or directory,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20073168/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com