mysql8.0:SQLSTATE[HY000] [2054] The server requested authentication method unknown to the client
忽然注意到的情况:
2018/7/19至2018/9/13之间发布的7.1.20、7.1.21、7.1.22和7.2.8、7.2.9、7.2.10这六个版本提供的对caching_sha2_password插件的支持,后续的版本中又取消了相关支持,不知道是因为什么。按照PHP官方的文档,目前似乎只有xdevapi可以支持caching_sha2_password插件。
使用PHP连接MySQL 8的时候,可能会发生如标题所示的错误:
SQLSTATE[HY000] [2054] The server requested authentication method unknown to the client
发生这种错误,是由于MySQL 8默认使用了新的密码验证插件:caching_sha2_password,而之前的PHP版本中所带的mysqlnd无法支持这种验证。解决这个问题,有两种办法。
一种办法是升级PHP支持MySQL 8的新验证插件。
PHP 7.2.8和PHP 7.1.20已经可以支持caching_sha2_password,直接连接MySQL 8。
截止PHP 7.0.31和PHP 5.6.37还无法支持caching_sha2_password,不知道后续版本是否会做出支持。
可以通过phpinfo()函数了解当前安装的PHP是否支持caching_sha2_password:

如果不能升级PHP,可以在MySQL 8中创建(或修改)使用caching_sha2_password插件的账户,使之使用mysql_native_password,这样先前版本的PHP就可以连接使用了。
- 在CREATE USER时,使用IDENTIFIED WITH xxx_plugin BY 'password',比如:
CREATE USER 'native'@'localhost' IDENTIFIED WITH mysql_native_password BY 'password!2#4';
- 使用ALTER USER修改已有账户的验证插件:
ALTER USER 'native'@'localhost' IDENTIFIED WITH mysql_native_password
或
ALTER USER 'native'@'localhost' IDENTIFIED WITH mysql_native_password BY 'new_password';
采用前一种方式,账户的密码将被清除;BY子句将为账户设置新的密码。
- /etc/my.cnf配置文件中,有一行:
# default-authentication-plugin=mysql_native_password
请删除注释符号“#”并重新启动mysqld使之生效,此后创建的账户均默认使用mysql_native_password。
- 如果您完成MySQL Server的安装之后,在没有启动过mysqld服务的情况下修改/etc/my.cnf配置,那么启动mysqld之后创建的'root'@'localhost'账户也是使用mysql_native_password插件的。
就这些,希望有帮助。
mysql8.0:SQLSTATE[HY000] [2054] The server requested authentication method unknown to the client的更多相关文章
- PHP错误:SQLSTATE[HY000] [2054] The server requested authentication method unknown to the client
使用PHP连接MySQL 8的时候,可能会发生如标题所示的错误: SQLSTATE[HY000] [2054] The server requested authentication method u ...
- PHP连接mysql8.0出错“SQLSTATE[HY000] [2054] The server requested authentication method unkno…
今天安装安装一个叫得推校园O2O系统的使劲都说连接不上服务器. 下面是安装说明,我直接进行3步骤,导入数据库配置文件,结果就显示题目报错的内容 安装说明: 直接输入程序目录即可 http://loca ...
- PHP连接mysql8.0出错“SQLSTATE[HY000] [2054] The server requested authentication method unknow.....
这个错可能是mysql默认使用 caching_sha2_password作为默认的身份验证插件,而不再是 mysql_native_password,但是客户端暂时不支持这个插件导致的. 解决方法一 ...
- php7.3连接MySQL8.0报错 PDO::__construct(): The server requested authentication method unknown to the client [caching_sha2_password]
报的错误: In Connection.php line : SQLSTATE[HY000] [] The server requested authentication method unknown ...
- Laravel - 解决连接MySQL时报"The server requested authentication method unknown to the client”错误
2019-04-12发布:hangge阅读:934 1,问题描述 最近建了个 Laravel 项目,当配置好 MySQL 数据库进行请求时,页面报如下错误: SQLSTATE[HY000] [ ...
- mysql 8.0 错误The server requested authentication method unknown to the client
mysql 安装了最新版本8.0.11后创建用户并授权后,授权的用户连接数据库提示 The server requested authentication method unknown to the ...
- PHP Warning: mysqli_connect(): The server requested authentication method unknown to the client [caching_sha2_password] in /usr/local/php/CreateDB.php on line 5
原因:php还不支持mysql8.0最新的密码加密方式 ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY ' ...
- Warning: mysqli_connect(): The server requested authentication method unknown to the client [caching_sha2_password]报错解决方法
错误: 解决方法:
- Docker mysql 连接 “The server requested authentication method unknown to the clien”错误
查了下,出现这个错误的原因是从mysql 5.6开始,mysql密码加密算法更改了. 我装的mysql 8.* ,那么有两种解决方法: mysql 版本选择 <= 5.6 修改密码 docker ...
随机推荐
- JavaScript 之 对话框
一.alert() 语法格式: alert("hello javascript"); 该对话框是弹出一个提示信息. Chrome 浏览器的效果. 二.prompt() 语法格式: ...
- Js字符串用法
js字符串整理导向图 ---欢迎收藏^ - ^
- NN入门
参考资料:https://blog.csdn.net/kwame211/article/details/77337166, 仅作为个人学习笔记.人工智能的底层模型是"神经网络"(n ...
- Oracle11g 干净卸载
原文链接:https://www.cnblogs.com/su-root/p/9689787.html 作 者:小柏 出 处:https://www.cnblogs.com/su-root Ora ...
- java 获取当前方法的被调用信息(被那个方法那个类那一行调用)
public void testMethod(){ Test1 t1 = new Test1(); t1.my(); } public static void main(String[] args) ...
- MySQL的JOIN连接
MySQL的JOIN join的含义跟英文单词"join"一样,连接连接两张表.分为 内连接:inner join 外连接 (1)左外连接(左边的表不加限制):left joi ...
- Tomcat get请求中文参数乱码
场景:使用Tomcat容器进行get方式传递中文参数到后台乱码. 原因:Tomcat默认的编码方式是ISO--. 解决方案: . 设置cofg-server.xml中的<Connector> ...
- 算法 翻转二叉树 dfs
翻转二叉树 翻转一棵二叉树.左右子树交换. Example 样例 1: 输入: {1,3,#} 输出: {1,#,3} 解释: 1 1 / => \ 3 3 样例 2: 输入: {1,2,3,# ...
- httprunner学习13-环境变量.env
前言 一般来说,在进行实际应用的开发过程中,应用会拥有不同的运行环境,通常会有以下环境: 本地开发环境 测试环境 生产环境 在不同环境中,我们可能会使用不同的数据库或邮件发送驱动等配置,这时候则需要通 ...
- 安全组与网络ACL
通过配置网络ACL和安全组策略,保障VPC内的弹性云服务器安全使用. 安全组对弹性云服务器进行防护:设置不同安全组访问规则实现系统访问控制 网络ACL对子网进行防护:可实现网络区域访问控制