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. [C++] 二叉树计算文件单词数

    目录 前置技能 构造和遍历二叉树 文件的打开.读取和写入 需求描述 读取文件 构建二叉树 格式化输入输出 具体实现 main.cpp binarytree.h binarytree.cpp 使用二叉树 ...

  2. English Grammar in Use - Part1 Present and past

    Unit 1 Present continuous (I am doing) A) Am/is/are + -ing is the Present continuous. B) I am doing ...

  3. Django框架学习易错和易忘点

    一.get在几处的用法 1.获取前端数据 request.POST.get('xxx') #当存在多个值时,默认取列表最后一个元素:所以当存在多个值时,使用getlist 2.获取数据库数据 mode ...

  4. OpenCV学习笔记3

    OpenCV学习笔记3 图像平滑(低通滤波) 使用低通滤波器可以达到图像模糊的目的.这对与去除噪音很有帮助.其实就是去除图像中的高频成分(比如:噪音,边界).所以边界也会被模糊一点.(当然,也有一些模 ...

  5. Docker 方式部署的应用的版本更新

    前言 公司使用 Docker-Compose 的方式部署 Jenkins/Gitlab/Sonar/Confluence/Apollo/Harbor/ELK/MySQL 等一系列开发工具/数据库. 而 ...

  6. 常用NLog配置

    <?xml version="1.0" encoding="utf-8" ?> <configuration> <configSe ...

  7. js按钮频繁提交解决方案:

    1.封装js: /// 函数节流 xhz.canRun = true; xhz.Throttling = function () { if (!xhz.canRun) { layer.msg('处理中 ...

  8. ReLU函数的缺陷

    ReLU激活功能并不完美. 它有一个被称为 “ReLU 死区” 的问题:在训练过程中,一些神经元会“死亡”,即它们停止输出 0 以外的任何东西.在某些情况下,你可能会发现你网络的一半神经元已经死亡,特 ...

  9. 【转】HTTP响应状态码参考簿

    HTTP响应状态码参考簿 http状态返回代码 1xx(临时响应)表示临时响应并需要请求者继续执行操作的状态代码. http状态返回代码 代码   说明100   (继续) 请求者应当继续提出请求. ...

  10. element-ui DatePicker 日期选择器 让结束日期大于开始日期

    element-ui  DatePicker 日期选择器 <el-date-picker v-model="addForm.startDate" type="dat ...