PHP错误: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插件的。
就这些,希望有帮助。
PHP错误:SQLSTATE[HY000] [2054] The server requested authentication method unknown to the client的更多相关文章
- 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_passw ...
- 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,但是客户端暂时不支持这个插件导致的. 解决方法一 ...
- 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 ...
- 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 ...
- Warning: mysqli_connect(): The server requested authentication method unknown to the client [caching_sha2_password]报错解决方法
错误: 解决方法:
- 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 ' ...
- Docker mysql 连接 “The server requested authentication method unknown to the clien”错误
查了下,出现这个错误的原因是从mysql 5.6开始,mysql密码加密算法更改了. 我装的mysql 8.* ,那么有两种解决方法: mysql 版本选择 <= 5.6 修改密码 docker ...
随机推荐
- SSM-SpringMVC-06:SpringMVC关于静态资源无法展示的问题
------------吾亦无他,唯手熟尔,谦卑若愚,好学若饥------------- 按照之前的那种方式一路走下来,或许你没发觉有问题,只是你没有使用到而已 css,js,图片等无法正常使用怎么 ...
- 全局唯一ID发号器的几个思路
标识(ID / Identifier)是无处不在的,生成标识的主体是人,那么它就是一个命名过程,如果是计算机,那么它就是一个生成过程.如何保证分布式系统下,并行生成标识的唯一与标识的命名空间有着密不可 ...
- Spring3.1 对Bean Validation规范的新支持(方法级别验证)
上接Spring提供的BeanPostProcessor的扩展点-1继续学习. 一.Bean Validation框架简介 写道Bean Validation standardizes constra ...
- js术语扫盲贴:XHR、RegExp、call-apply、prototype
(1) XHR:xml httprequestXHR注入:XHR 注入技术是通过XMLHttpRest来获取javascript的.但与eval不同的是,该机制是通过创建一个script的DOM元素, ...
- Load balancer does not have available server for client
最近在研究spring-cloud,研究zuul组件时发生下列错误: Caused by: com.netflix.client.ClientException: Load balancer does ...
- Reactor模式的.net版本简单实现--DEMO
近期在学习DotNetty,遇到不少的问题.由于dotnetty是次netty的.net版本的实现.导致在网上叙述dotnetty的原理,以及实现技巧方面的东西较少,这还是十分恼人的.在此建议学习和使 ...
- 7-14 backbone源码
_.extend = function(obj) { // each循环参数中的一个或多个对象 each(slice.call(arguments, 1), function(source) { // ...
- pip 安装mysqlclient报错OSError: mysql_config not found
执行 pip install mysqlclient 报错信息如下: [root@CentOS7-demo bin]# pip install mysqlclient Collecting mysql ...
- [Usaco2015 Jan]Grass Cownoisseur 图论 tarjan spfa
先缩点,对于缩点后的DAG,正反跑spfa,枚举每条边进行翻转即可 #include<cstdio> #include<cstring> #include<iostrea ...
- 【小白学C#】谈谈C#多播委托因异常而终止的解决方案
一.前言 前几天,马三在与朋友闲聊技术的时候,朋友忽然抛出一个问题,把马三难倒了,本着求知的精神,回来以后马三就查阅了相关资料并做了一些实验,终于把问题搞明白了,因此写下本篇博客记录一下.首先,问题是 ...