切换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] [email protected]
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
在项目中使用新用户