2019-04-12发布:hangge阅读:934

 

1,问题描述

最近建了个 Laravel 项目,当配置好 MySQL 数据库进行请求时,页面报如下错误:
 
SQLSTATE[HY000] [2054] The server requested authentication method unknown to the client (SQL: select * from user where id = 3)
Previous exceptions

  • SQLSTATE[HY000] [2054] The server requested authentication method unknown to the client (2054)
  • PDO::__construct(): The server requested authentication method unknown to the client [caching_sha2_password] (0)
 

2,问题原因

(1)过去 MySQL 的密码认证插件是“mysql_native_password”。
(2)而当 mysql 到了 8.0 版以上时,密码认证插件使用的是“caching_sha2_password”。可是当前有很多数据库工具和链接包都不支持这个。
 

3,解决办法

修改密码认证方式,改回“mysql_native_password”认证插件。
 

4,操作步骤

(1)首先编辑 mysql 配置文件。由于我用的是 mac 电脑,安装后默认是没有这个配置文件的,执行如下命令添加配置文件:

1
sudo vi /etc/my.cnf

(2)按下 i 进入编辑模式,添加如下内容(把加密模式改成旧的):

1
2
[mysqld]
default_authentication_plugin=mysql_native_password

(3)最后按下 esc 退出编辑模式。 接着组合按下 shift + : 开启命令,然后输入 wq 回车,保存退出。

 
(4)由于原来创建的用户(比如 root)还是使用新的验证方式,我们还需将它们改成老的。首先使用命令行连接数据库:

1
mysql -u root -p

(5)登录后依次执行下面三个命令(其中密码部分根据情况自行修改):

1
2
3
ALTER USER 'root'@'localhost' IDENTIFIED BY '密码' PASSWORD EXPIRE NEVER;
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '密码';
FLUSH PRIVILEGES;

(6)完毕后重启 MySQL 服务可以发现,PHP 这边已经可以成功连接数据库了。

原文出自:www.hangge.com  转载请保留原文链接:https://www.hangge.com/blog/cache/detail_2331.html

Laravel - 解决连接MySQL时报"The server requested authentication method unknown to the client”错误的更多相关文章

  1. mysql 8.0 错误The server requested authentication method unknown to the client

    mysql 安装了最新版本8.0.11后创建用户并授权后,授权的用户连接数据库提示 The server requested authentication method unknown to the ...

  2. 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 ...

  3. 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 ...

  4. 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 ...

  5. Docker mysql 连接 “The server requested authentication method unknown to the clien”错误

    查了下,出现这个错误的原因是从mysql 5.6开始,mysql密码加密算法更改了. 我装的mysql 8.* ,那么有两种解决方法: mysql 版本选择 <= 5.6 修改密码 docker ...

  6. Warning: mysqli_connect(): The server requested authentication method unknown to the client [caching_sha2_password]报错解决方法

    错误: 解决方法:

  7. 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 ' ...

  8. PHP连接mysql8.0出错“SQLSTATE[HY000] [2054] The server requested authentication method unkno…

    今天安装安装一个叫得推校园O2O系统的使劲都说连接不上服务器. 下面是安装说明,我直接进行3步骤,导入数据库配置文件,结果就显示题目报错的内容 安装说明: 直接输入程序目录即可 http://loca ...

  9. 使用navicat连接mysql时报错:2059 - authentication plugin 'caching_sha2_password'

    首先从本地登录mysql数据库,进入mysql控制台,输入如下命令: ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_passwo ...

随机推荐

  1. echarts饼状图位置设置

    series: { name: "流量占比分布", type: "pie", radius: ["40%", "60%" ...

  2. oracle update left join 写法

    oracle update left join 写法 (修改某列,条件字段在关联表中) 案例: E:考核表 X,:用户表 USERNAME 关联 需求:修改营业部最高分 分析:通过登录账号的营业部OR ...

  3. 用ASP.NET Web API技术开发HTTP接口(一)

    开发工具 Visual Studio 2013 SQL Server 2008 R2 准备工作 启动Visual Studio 2013,新建一个ASP.NET Web应用程序,命名为SimpleAP ...

  4. Java架构笔记:用JWT对SpringCloud进行认证和鉴权

    写在前面 喜欢的朋友可以关注下专栏:Java架构技术进阶.里面有大量batj面试题集锦,还有各种技术分享,如有好文章也欢迎投稿哦. image.png JWT(JSON WEB TOKEN)是基于RF ...

  5. MySQL 乱码问题解决

    修改 配置文件 只需留下 my.ini文件,然后修改其编码配置. 配置如下 # Example MySQL config file for large systems. # # This is for ...

  6. 基于【 springBoot+jsoup】一 || 爬取全国行政区划数据

    一.代码演示 如果中途中断,可进行刷选过滤已拉取省份数据 /** * TODO * * @author kevin * @createTime 2019-11-18 19:37 */ @RestCon ...

  7. SDcms1.8代码审计

    由于工作原因,分析了很多的cms也都写过文章,不过觉得好像没什么骚操作都是网上的基本操作,所以也就没发表在网站上,都保存在本地.最近突然发现自己博客中实战的东西太少了,决定将以前写的一些文章搬过来,由 ...

  8. SQL SERVER-Extendevent

    事件类介绍 https://docs.microsoft.com/zh-cn/previous-versions/sql/sql-server-2008/ms188275(v=sql.100)

  9. Linux下制作静态库 & 动态库

    静态库 1.将.c生成.o文件 gcc-cadd.c-o add.o 2.使用ar工具制作静态库 ar rcs lib库名.a add.o sub.o div.o 3.编译静态库到可执行文件中 gcc ...

  10. ES6中let、const和var的区别

    一.let 1.基本用法 ES6 新增了let命令,用来声明变量. let 的用法类似于 var,但所声明的变量只在 let 命令所在的代码块内有效(一个“{}”相当于一个代码块) { let a = ...