切换mysql8.0报错
切换mysql8.0后报错 SQLSTATE[HY000] [2054] The server requested authentication method unknown to the client
SQLSTATE[HY000] [2054] The server requested authentication method unknown to the client
原因:PHP的一个bug
mysql 升级了caching_sha2_password php
无法识别
[2019-12-27 15:45 UTC] nikic@php.net
Closing this as caching_sha2_password is in principle supported on 7.4 -- though there are a couple of different bugs that may affect it, tracked at bug #78981 and bug #79011.
解决方案:
方案一、修改配置文件database.php
// database.php
'connections' => [
'mysql' => [
'driver' => 'mysql',
'host' => env( 'DB_HOST', '127.0.0.1' ),
'port' => env( 'DB_PORT', '3306' ),
'database' => env( 'DB_DATABASE', 'forge' ),
'username' => env( 'DB_USERNAME', 'forge' ),
'password' => env( 'DB_PASSWORD', '' ),
'unix_socket' => env( 'DB_SOCKET', '' ),
'charset' => 'utf8mb4',
'collation' => 'utf8mb4_unicode_ci',
'prefix' => '',
'strict' => true,
'engine' => null,
'modes' => [
'ONLY_FULL_GROUP_BY',
'STRICT_TRANS_TABLES',
'NO_ZERO_IN_DATE',
'NO_ZERO_DATE',
'ERROR_FOR_DIVISION_BY_ZERO',
'NO_ENGINE_SUBSTITUTION',
],
],
],
方案二、如果你使用的是docker:
services:
mysql:
image: mysql:latest
command:
- "--default-authentication-plugin=mysql_native_password"
...
方案三、修改mysql配置
- 命令行输入
mysql
- 输入下面命令
ALTER USER '你的用户名'@'localhost' IDENTIFIED WITH mysql_native_password BY '你的密码';
- 不想设置密码可以留空.
.env
在项目中使用新用户
你要保守你心,胜过保守一切。
本文来自博客园,作者:刘俊涛的博客,转载请注明原文链接:https://www.cnblogs.com/lovebing/p/16784361.html
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
2019-10-12 新零售下的 AI智能货柜
2017-10-12 U盘启动盘恢复为普通盘
2017-10-12 EXCel鼠标右键不能用解决办法