切换mysql8.0报错

切换mysql8.0后报错 SQLSTATE[HY000] [2054] The server requested authentication method unknown to the client

image-20221012140857474

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配置

  1. 命令行输入mysql
  2. 输入下面命令
    ALTER USER '你的用户名'@'localhost' IDENTIFIED WITH mysql_native_password BY '你的密码';
  3. 不想设置密码可以留空.
  4. .env在项目中使用新用户
posted @   刘俊涛的博客  阅读(49)  评论(0编辑  收藏  举报
历史上的今天:
2019-10-12 新零售下的 AI智能货柜
2017-10-12 U盘启动盘恢复为普通盘
2017-10-12 EXCel鼠标右键不能用解决办法
Servbay
点击右上角即可分享
微信分享提示