php myqli_connect失败。服务器请求客户端未知的身份验证方法[caching_sha2_password]

时间:2018-10-09 17:15:12

标签: php mysql apache

我正在运行php 7.3。运行以下代码:

$conn = mysqli_connect($servername, $username, $hashed_password);

if(!$conn){
    die("Connection failed: " . mysqli_connect_error());
}

我得到的输出为:

Warning: mysqli_connect(): The server requested authentication method unknown to the client [caching_sha2_password] in C:\localhost\mysql.php on line x

Warning: mysqli_connect(): (HY000/2054): The server requested authentication method unknown to the client in C:\localhost\mysql.php on line x
Connection failed: The server requested authentication method unknown to the client.

修复?

1 个答案:

答案 0 :(得分:0)

这是因为PHP尚不支持MySQL 8+中的caching_sha2_password方法。解决方法是,您可以更改数据库中使用的密码加密,也可以还原到PHP 7.2.8,该版本对此具有临时支持,直到在下一版本中再次将其删除为止。

有关该主题的讨论,以供将来参考: https://github.com/phpmyadmin/phpmyadmin/issues/14220#issuecomment-434125682

http://php.net/manual/en/mysqli.requirements.php

https://github.com/php/php-src/commit/d6e81f0bfd0cb90586dd83d4fd47a4302605261a#commitcomment-30380461