php mysqli_connect:客户端未知的身份验证方法 [caching_sha2_password] [英] php mysqli_connect: authentication method unknown to the client [caching_sha2_password]
问题描述
我正在使用 php mysqli_connect
登录 MySQL 数据库(全部在本地主机上)
I am using php mysqli_connect
for login to a MySQL database (all on 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 表:
this is the mysql.user table:
MySQL 服务器 ini 文件:
MySQL Server ini File:
[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 登录;
with caching_sha2_password
in the MySQL Server ini file, it's not possible at all to login with user1 or user2;
error: mysqli_connect(): 服务器请求了客户端未知的身份验证方法 [caching_sha2_password] in...
error: mysqli_connect(): The server requested authentication method unknown to the client [caching_sha2_password] in...
在MySQL Server ini文件中使用mysql_native_password
,可以用user1登录,但用user2登录,同样报错;
with mysql_native_password
in the MySQL Server ini file, it's possible to login with user1, but with user2, same error;
如何在 mySql Server 上使用 caching_sha2_password
登录?
how can I login using caching_sha2_password
on the mySql Server?
推荐答案
从 PHP 7.4 开始,这不再是问题.mysqlnd 添加了对 caching_sha2
身份验证方法的支持.
As of PHP 7.4, this is no longer an issue. Support for caching_sha2
authentication method has been added to mysqlnd.
目前,PHP mysqli 扩展不支持新的 caching_sha2 身份验证功能.你必须等到他们发布更新.
Currently, PHP mysqli extension do not support new caching_sha2 authentication feature. You have to wait until they release an update.
查看 MySQL 开发者的相关帖子:https://mysqlserverteam.com/upgrading-to-mysql-8-0-default-authentication-plugin-考虑/
Check related post from MySQL developers: https://mysqlserverteam.com/upgrading-to-mysql-8-0-default-authentication-plugin-considerations/
他们没有提到 PDO,也许你应该尝试与 PDO 联系.
They didn't mention PDO, maybe you should try to connect with PDO.
这篇关于php mysqli_connect:客户端未知的身份验证方法 [caching_sha2_password]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!