解决 SQLSTATE[HY000] [2054] The server requested authentication method unknown to the client
连接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(图1) 解决 SQLSTATE[HY000] [2054] The server requested authentication method unknown to the client](https://asset.appfiles.xyz/d/file/20200322/6109528c38eeb73962c2a51d312f9369.png)
原因
由于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(图2) 解决 SQLSTATE[HY000] [2054] The server requested authentication method unknown to the client](https://asset.appfiles.xyz/d/file/20200322/c84c30a04448b17e1d9a266a29ccc1b0.png)
解决方法二
MySQL 8中创建(或修改)使用caching_sha2_password插件的账户,使之使用mysql_native_password。
- 在
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插件的。
也可以直接在客户端修改如图:
![解决 SQLSTATE[HY000] [2054] The server requested authentication method unknown to the client(图3) 解决 SQLSTATE[HY000] [2054] The server requested authentication method unknown to the client](https://asset.appfiles.xyz/d/file/20200322/9eb1d0bf3e3ba4073a5865a6afaf611f.png)
栏 目:其它数据库
本文标题:解决 SQLSTATE[HY000] [2054] The server requested authentication method unknown to the client
本文地址:https://zz.feitang.co/shujuku/28648.html
您可能感兴趣的文章
- 12-22使用mysql记录从url返回的http GET请求数据操作
- 12-22详解sql中exists和in的语法与区别
- 12-22hive从mysql导入数据量变多的解决方案
- 12-22如何为PostgreSQL的表自动添加分区
- 12-22postgresql 实现得到时间对应周的周一案例
- 12-22sqoop export导出 map100% reduce0% 卡住的多种原因及解决
- 12-22mysql查询条件not in 和 in的区别及原因说明
- 12-22解决mysql使用not in 包含null值的问题
- 12-22解决从集合运算到mysql的not like找不出NULL的问题
- 12-22postgresql 实现多表关联删除


阅读排行
推荐教程
- 12-11mysql代码执行结构实例分析【顺序、分支、循环结构】
- 12-08添加mysql的用户名和密码是什么语句?
- 12-20PhpMyAdmin出现错误数据无法导出怎么办?
- 12-19Redis中实现查找某个值的范围
- 12-15浅析mysql迁移到clickhouse的5种方法
- 12-15CentOS7 64位下MySQL5.7安装与配置教程
- 12-14Mysql大型SQL文件快速恢复方案分享
- 12-14mysql 5.7.27 安装配置方法图文教程
- 12-13MySQL给新建用户并赋予权限最简单的方法
- 12-13关于MySQL索引的深入解析





