PHP mysqli_connect : authentication method unknown to the client [caching_sha2_password]

标签 php mysql hash sha

我正在使用 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.user 表: mysql.user table

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/59203585/

相关文章:

javascript - 如何使用 Javascript 或 html ID 更改部分 HTML 'form action: link' 元素

mysql - sql 没有显示正确的结果

c++ - C2338 : The C++ Standard doesn't provide a hash for this type with string and unique_ptr

php - $_GET ['code' 的来源] 以获取 youtube api 凭据的刷新 token

php - 基于 Woocommerce 中用户总购买量的自定义购物车通知

php - 第二个 AJAX 调用卸载第一个的结果

Mysql 查询不在 WHERE 上返回结果,而是在 AND 上返回结果

mysql - 数据库经过优化,可搜索大量具有不同属性的对象

ruby db结果集到散列中的数组

javascript - 从js中的两个数组中删除重复的哈希?