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 ...
随机推荐
- java项目中通过添加filter过滤器解决ajax跨域问题
1.在web.xml添加filter <filter> <filter-name>contextfilter</filter-name> <filter-cl ...
- adb常用操作命令
1.adb简介: adb,即 Android Debug Bridge.通过这个工具和android进行交互操作 2.adb命令格式: adb [-d|-e|-s <serialNu ...
- django(权限、认证)系统——用户Login,Logout
上面两篇文章,讲述的Django的Authentication系统的核心模型对象User API和相关的使用,本文继续深入,讨论如何在Web中使用Authentication系统. 前面说了,Djan ...
- Java一次读取文本文件所有内容
转自https://www.cnblogs.com/longronglang/p/7458027.html#undefined 我们做文本处理的时候的最常用的就是读写文件了,尤其是读取文件,不论是什么 ...
- BZOJ_2743_[HEOI2012]采花_离线+树状数组
BZOJ_2743_[HEOI2012]采花_离线+树状数组 Description 萧芸斓是Z国的公主,平时的一大爱好是采花.今天天气晴朗,阳光明媚,公主清晨便去了皇宫中新建的花园采花 .花园足够大 ...
- layer的删除询问框的使用
删除是个很需要谨慎的操作 我们需要进行确认 对了删除一般使用ajax操作 因为如果同url请求 处理 再返回 会有空白页 1.js自带的样式 <button type="button& ...
- 你可能忽略的js类型转换
前言 相信刚开始了解js的时候,都会遇到 2 == '2',但 1+2 == 1+'2'为false的情况.这时候应该会是一脸懵逼的状态,不得不感慨js弱类型的灵活让人发指,隐式类型转换就是这么猝不及 ...
- Linux上好用的工具集合
1.截图工具 WIndows下有Snipaste,Ubuntu自带的截图工具不能涂鸦等,不好用.Linux下可以使用deepin-screenshot(深度截图,https://www.deepin. ...
- (6)STM32使用HAL库实现modbus的简单通讯
1.判断地址.校验 2.读取本机数据并校验打包 3.发送数据包 4.本机数据长度比要读取的长度短怎么办 4.校验错误怎么办
- 利用FT232实现USB转串口
FT232B数据手册:http://www.ftdichip.com/Support/Documents/DataSheets/ICs/DS_FT232BL_BQ.pdf 常用的USB转串口的芯片有F ...