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++ new/delete详解及原理

    学了冯诺依曼体系结构,我们知道: 硬件决定软件行为,数据都是围绕内存流动的. 可想而知,内存是多么重要.当然,我们这里说的内存是虚拟内存(详情看Linxu壹之型). 1.C/C++内存布局 2.C语言 ...

  2. chrome下载离线安装包

    chrome下载离线安装包 - codeflyto - 博客园 下载页面:

  3. SAS学习笔记51 SAS数据集

    结构 SAS数据集是关系型的,包含两个部分:描述部分(变量)和数据部分(观察值) 形式 SAS系统中共有两种类型的数据集: 1.SAS 数据文件(SAS datafiles) 2.SAS 数据视窗(S ...

  4. Spring Boot 集成 Swagger生成接口文档

    目的: Swagger是什么 Swagger的优点 Swagger的使用 Swagger是什么 官网(https://swagger.io/) Swagger 是一个规范和完整的框架,用于生成.描述. ...

  5. Spring Boot使用@ConfigurationProperties注解获取配置文件中的属性值

    注意:这种方式要提供属性的getter/setter方法—— 如果idea报错,提示没有相应的执行器,就需要在maven中添加: (虽然不配置代码也能正常运行,作用在下面会说明) 配置了该执行器后,在 ...

  6. bootstrap栅格系统的container和row一些关系

    container有个15px的padding,而我们设定的每个col也都有15px的padding,如果两者直接配合,那么就会产生30px的间距,导致内容和浏览器边框的距离较大,所以用row将所有的 ...

  7. 怎样获取全局对象 window

    1. 使用window.self window.self === window; // true 2. 使用window.window window.window === window; // tru ...

  8. springboot_1

    1. 创建一个spring boot项目可以使用哪些工具 1.1 使用start.spring.io 这是一个网站,可以在这个网站选择你需要的组件,然后会自动生成一个项目文件,你可以将它下载到本地,然 ...

  9. visualSVN server 安装成功,但是无法连接,url打不开

    转自:https://www.oschina.net/question/878142_91825 点击开始–>程序->VisualSVN–>VisuaSVN Server Manag ...

  10. django_rest framework 接口开发(一)

    1 restful 规范(建议) 基于FbV def order(request): if request.method=="GET": return HttpResponse(' ...