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

问题描述

我正在尝试在我的 Mac 上安装 vanilla 论坛,为此我刚刚从 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:没有那个文件或目录

知道我哪里出错了吗?

推荐答案

好的,我刚刚找到了解决方案.问题原来是主机不应该是 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): 没有那个文件或目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-04 00:03