我正在使用 php mysqli_connect
登录 MySQL 数据库(全部在本地主机上)
<?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 服务器 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 服务器上使用 caching_sha2_password
登录?
最佳答案
我通过 SQL 命令解决了这个问题:
ALTER USER 'mysqlUsername'@'localhost' IDENTIFIED WITH mysql_native_password BY 'mysqlUsernamePassword';
被 https://dev.mysql.com/doc/refman/8.0/en/alter-user.html 引用
如果您正在创建新用户
CREATE USER 'jeffrey'@'localhost' IDENTIFIED WITH mysql_native_password BY 'password';
被 https://dev.mysql.com/doc/refman/8.0/en/create-user.html 引用
这对我有用
关于PHP mysqli_connect : authentication method unknown to the client [caching_sha2_password],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58906232/