dqiaw48488 2019-03-05 21:39 采纳率: 0%
浏览 1944

警告:mysqli :: __ construct():( HY000 / 2002):没有这样的文件或目录

我花了几天的时间才想办法解决这个问题... 我在运行Mojave(10.14.3)的Mac OS上设置了Apache Web服务器(版本2.4.34),并安装了当前版本的MySQL Community Server(8.0.15)。 正如我所能确定的(从命令行),两者都运行良好。 我已经安装了PHP 7.1.23。 当我使用以下代码创建.php文件并将其放在我的Sites目录中,然后在Safari中转到http://localhost/~dave/hello.php时,出现此错误::

"Warning: mysqli::__construct(): (HY000/2002): No such file or directory in /Users/dave/Sites/hello.php on line 7 Connection failed: No such file or directory".

hello.php中的代码:

<?php
$servername = "localhost";
$username = "dave";
$password = "*****";

//Create connection
$conn = new mysqli($servername, $username, $password);

//Check connection
if ($conn->connect_error) {
   die("Connection failed: " . $conn->connect_error);
}
echo "Connected successfully";
?>

我已经尝试了所有我能想到的一切,包括其他两篇类似的文章中的建议(这一篇:我的数据库用户存在,但是我仍然得到(HY000 / 2002):没有这样的文件或目录,而这一篇:PHP警告: mysqli :: construct():(HY000 / 2002):没有这样的文件或目录(Debian GNU / Linux 9),并且我无法使用php连接到MySQl。 特别是,我检查了php info页面,并给出了mysqli的套接字为 /tmp/mysql.sock。 我尝试通过添加每个套接字(代替空值)来更改php.ini.default文件,但两个都不起作用(仍然产生相同的错误)。 我以为2002 MySQL套接字错误可能是问题所在,所以我做了一个符号链接is:

sudo mkdir /var/mysql
sudo ln -s /tmp/mysql.sock /var/mysql/mysql.sock

但是这样做只会产生一个新的错误:

Warning: mysqli::__construct(): The server requested authentication method unknown to the client [caching_sha2_password] in /Users/dave/Sites/hello.php on line 7

Warning: mysqli::__construct(): (HY000/2054): The server requested authentication method unknown to the client in /Users/dave/Sites/hello.php on line 7 Connection failed: The server requested authentication method unknown to the client

所以我删除了符号链接...并返回到原始错误。 我还尝试使用IP地址127.0.0.1以及其他问题线程建议的“ localhost:3306”替换“ localhost”。 这里也没有任何作用。 请帮助我,我对这种计算机/网页设计的使用是陌生的,我没有明显的选择(谷歌/可理解)。s.

  • 写回答

1条回答

  • dtwxmn8741 2019-03-19 17:17
    关注

    I got some help from some local tech guys in my area and it turns out that fixing the socket error was the first step, like I tried to do above. I eventually did it this way, using the solution by noun:

    Warning: mysql_connect(): [2002] No such file or directory (trying to connect via unix:///tmp/mysql.sock) in

    The second error message was then generated (same one as in my question, here again):

    mysqli::__construct(): The server requested authentication method unknown to the client [caching_sha2_password] in /Users/dave/Sites/hello.php on line 7

    Warning: mysqli::__construct(): (HY000/2054): The server requested authentication method unknown to the client in /Users/dave/Sites/hello.php on line 7

    This was fixed by the SQL-based solution (June 9 2018 answer) to this question:

    php mysqli_connect: authentication method unknown to the client [caching_sha2_password]

    This SQL statement was simply run in MySQL from the terminal. After restarting the Apache server I reloaded the .php file in Safari and this resulted in a successful mysqli connection to MySQL with PHP. I also tried a PDO connection and this also worked.

    评论

报告相同问题?

悬赏问题

  • ¥15 Qt下使用tcp获取数据的详细操作
  • ¥15 idea右下角设置编码是灰色的
  • ¥15 全志H618ROM新增分区
  • ¥15 在grasshopper里DrawViewportWires更改预览后,禁用电池仍然显示
  • ¥15 NAO机器人的录音程序保存问题
  • ¥15 C#读写EXCEL文件,不同编译
  • ¥15 MapReduce结果输出到HBase,一直连接不上MySQL
  • ¥15 扩散模型sd.webui使用时报错“Nonetype”
  • ¥15 stm32流水灯+呼吸灯+外部中断按键
  • ¥15 将二维数组,按照假设的规定,如0/1/0 == "4",把对应列位置写成一个字符并打印输出该字符