警告:mysqli_connect():(HY000/2002):没有这样的文件或目录 [英] Warning: mysqli_connect(): (HY000/2002): No such file or directory

查看:625
本文介绍了警告:mysqli_connect():(HY000/2002):没有这样的文件或目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm trying to install vanilla forums on my Mac, and for this I just created a database and a user from the MySQL command line:

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)

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

So I try to connect using the following code:

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

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

but unfortunately, I get an error saying

警告:mysqli_connect():(HY000/2002):在第3行的/Users/kramer65/Sites/vanilla/info.php中没有这样的文件或目录 无法连接到MySQL:没有这样的文件或目录

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

知道我要去哪里哪里吗?

Any idea where I'm going wrong?

推荐答案

好的,我刚刚找到了解决方案.问题原来是主机不应该是localhost,而应该是127.0.0.1.我一直以为localhost127.0.0.1是相同的,但事实证明是不同的.

Alright, I just found the solution. The problem turned out to be that the host shouldn't have been localhost, but 127.0.0.1. I always thought localhost and 127.0.0.1 was the same, but it turned out to be different.

因此,作为未来用户的提示,如有疑问,请始终使用ip.

So maybe as a tip for future users, always use the ip when in doubt.

这篇关于警告:mysqli_connect():(HY000/2002):没有这样的文件或目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆