php mysqli_connect:客户端未知的身份验证方法[caching_sha2_password]

我使用php mysqli_connect登录MySQL数据库(全部在localhost上)

<?php
//DEFINE ('DB_USER', 'user2');
//DEFINE ('DB_PASSWORD', 'pass2');
DEFINE ('DB_USER', 'user1');
DEFINE ('DB_PASSWORD', 'pass1');
DEFINE ('DB_HOST', '127.0.0.1');
DEFINE ('DB_NAME', 'dbname');

$dbc = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME);

if(!$dbc){
    die('error connecting to database');    
}
?>

这是mysql.user表:
php mysqli_connect:客户端未知的身份验证方法[caching_sha2_password]

MySQL Server ini文件:

[mysqld]
# The default authentication plugin to be used when connecting to the server
default_authentication_plugin=caching_sha2_password
#default_authentication_plugin=mysql_native_password

使用MySQL Server ini文件中的caching_sha2_password,根本无法使用user1或user2登录;

error: mysqli_connect(): The server requested authentication method unknown to the client [caching_sha2_password] in…

使用MySQL Server ini文件中的mysql_native_password,可以使用user1登录,但是使用user2,同样的错误;

如何在mySql Server上使用caching_sha2_password登录?

解决方法:

目前,php mysqli扩展不支持新的caching_sha2身份验证功能.
您必须等到他们发布更新.

查看mysql开发人员的相关帖子:https://mysqlserverteam.com/upgrading-to-mysql-8-0-default-authentication-plugin-considerations/

他们没有提到PDO,也许你应该尝试与PDO联系.

上一篇:MD5 For Windows


下一篇:TEC-007 java和php SHA-256 签名和延签