欢迎来到站长天空!

其它数据库

当前位置: 主页 > 数据库 > 其它数据库

解决 SQLSTATE[HY000] [2054] The server requested authentication method unknown to the client

时间:2025-12-05 15:00:02|栏目:其它数据库|点击:

连接MYSQL数据库时报错:

SQLSTATE[HY000] [2054] The server requested authentication method unknown to the client

解决 SQLSTATE[HY000] [2054] The server requested authentication method unknown to the client

原因

由于MySQL 8默认使用了新的密码验证插件:caching_sha2_password,而低版本的PHP版本中所带的mysqlnd无法支持这种验证。故报“请求客户端未知的身份验证方法”。

解决方法一

升级PHP支持MySQL 8的新验证插件。

7.1.20 - PHP 7.2.8或更高版本PHP已经可以支持caching_sha2_password,直接连接MySQL 8。检查你的PHP版本以确定问题。

可以通过phpinfo()函数了解当前安装的PHP是否支持caching_sha2_password:

解决 SQLSTATE[HY000] [2054] The server requested authentication method unknown to the client

解决方法二

MySQL 8中创建(或修改)使用caching_sha2_password插件的账户,使之使用mysql_native_password。

  1. CREATE USER时,使用IDENTIFIED WITH xxx_plugin BY ‘password‘,比如:CREATE USER 'native'@'localhost' IDENTIFIED WITH mysql_native_password BY 'password!2#4';
  2. 使用ALTER USER修改已有账户的验证插件:ALTER USER 'native'@'localhost' IDENTIFIED WITH mysql_native_passwordALTER USER 'native'@'localhost' IDENTIFIED WITH mysql_native_password BY 'new_password';采用前一种方式,账户的密码将被清除;BY子句将为账户设置新的密码。
  3. /etc/my.cnf配置文件中,有一行:# default-authentication-plugin=mysql_native_password请删除注释符号“#”并重新启动mysqld使之生效,此后创建的账户均默认使用mysql_native_password
  4. 如果您完成MySQL Server的安装之后,在没有启动过mysqld服务的情况下修改/etc/my.cnf配置,那么启动mysqld之后创建的‘root‘@‘localhost‘账户也是使用mysql_native_password插件的。

也可以直接在客户端修改如图:

解决 SQLSTATE[HY000] [2054] The server requested authentication method unknown to the client

上一篇:解决MySQL8 #1227 – Access denied; you need (at least one of) the SYSTEM_USER privilege(s) for this ope

栏    目:其它数据库

下一篇:mysql的事务,隔离级别和锁用法实例分析

本文标题:解决 SQLSTATE[HY000] [2054] The server requested authentication method unknown to the client

本文地址:https://zz.feitang.co/shujuku/28648.html

广告投放 | 联系我们 | 版权申明

申明:本站所有的文章、图片、评论等,均由网友发表或上传并维护或收集自网络,属个人行为,与本站立场无关。

如果侵犯了您的权利,请与我们联系,我们将在24小时内进行处理、任何非本站因素导致的法律后果,本站均不负任何责任。

联系QQ:257218569 | 邮箱:257218569@qq.com

Copyright © 2018-2025 站长天空 版权所有 Powered by EyouCms冀ICP备14023439号