php mysqli_connect:客户端未知的身份验证方法[caching_sha2_password] [英] php mysqli_connect: authentication method unknown to the client [caching_sha2_password]

查看:144
本文介绍了php mysqli_connect:客户端未知的身份验证方法[caching_sha2_password]的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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 Server 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;

错误:mysqli_connect():服务器在...中请求客户端[caching_sha2_password]未知的身份验证方法

在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起,这不再是问题.

当前,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/upgradeing-to-mysql-8-0-default-authentication-plugin-considerations/

Check related post from mysql developers : https://mysqlserverteam.com/upgrading-to-mysql-8-0-default-authentication-plugin-considerations/

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

They didnt mention PDO, maybe you should try to connect with PDO.

这篇关于php mysqli_connect:客户端未知的身份验证方法[caching_sha2_password]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆