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 ...
随机推荐
- Palo Alto GlobalProtect上的PreAuth RCE
0x00 前言 SSL VPN虽然可以保护企业资产免受互联网被攻击的风险影响,但如果SSL VPN本身容易受到攻击呢?它们暴露在互联网上,可以可靠并安全地连接到内网中.一旦SSL VPN服务器遭到入侵 ...
- 5.2 odex文件
odex是OptimizedDEX的缩写,是优化过的dex文件 odex两种存在方式: 1. 从apk程序中提取,和apk文件放在一起,后缀 odex,此类文件多是AndroidRom系统文件 2. ...
- 上传文本到hdfs上的一些命令
在hadoop下创建文件夹 bin/hdfs dfs -mkdir -p /usr/hadoop/spark/ touch wc.input 写一些文本进去. 上传到hdfs上 bin/hdfs ...
- NumPy 之 面向数组编程
import numpy as np Using NumPy arrays enables you to express many kinds of data processing tasks as ...
- VS code key shortcuts for windows
mac上的快捷键,尽量是选择像我用vs studio上靠近. ctrl+K+S: 显示快捷键列 ctrl+shift+p: 系统配置命令行 ctrl+p:项目中文件列表,选择文件 Alt+M:当前文件 ...
- php mysql 按照指定年月查找数据 数据库create_time为时间戳
$moneyloglist = MoneyLog::where(['user_id' => $this->auth->id]) ->where($where) ->whe ...
- 【干货】gitlab-11.10.4版本汉化
目录 1.YUM安装gitlab-11.10.4 2.gitlab汉化技能 1.YUM安装gitlab-11.10.4 下载gitlab-ce的repo [root@localhost ~]# cur ...
- VMware虚拟化kvm安装部署总结
虚拟化 1.环境 Centos7.3 关闭selinux,关闭防火墙 2.虚拟化环境配置 2.1 kvm部署安装 1. VMware 配置桥接模式 2.bios开启虚拟机,以本地台式机为例, 重启动电 ...
- php一句话木马+中国菜刀拿服务器文件目录
使用工具: 中国菜刀 一句话php木马 <?php @eval($_POST['123456']);?> 第一步,将php木马上传至服务器,为了方便我就直接在服务器上建立. [root@p ...
- dfs 全排列 使用交换——含重复元素和非重复元素
15. 全排列 中文 English 给定一个数字列表,返回其所有可能的排列. 样例 样例 1: 输入:[1] 输出: [ [1] ] 样例 2: 输入:[1,2,3] 输出: [ [1,2,3], ...