我正在运行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.


固定?

最佳答案

这是因为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

关于php - php myqli_connect失败。服务器请求客户端未知的身份验证方法[caching_sha2_password],我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/52726205/

10-10 18:36
查看更多