Featured image of post 解决 MySQL 8 Docker 无法登入错误:Authentication plugin 'caching_sha2_password' cannot be loaded

解决 MySQL 8 Docker 无法登入错误:Authentication plugin 'caching_sha2_password' cannot be loaded

解决 MySQL 8 Docker 无法登入错误:Authentication plugin 'caching_sha2_password' cannot be loaded

原因

在使用 docker-compose 安装 MySQL 8 (mysql/mysql-server:8) 后,要连线登入时,会出现下列讯息

Authentication plugin ‘caching_sha2_password’ cannot be loaded

version: '3.9'

networks:
    local-proxy-network:
        driver: bridge


services:
    mysql:
        container_name: local_mysql
        image: 'mysql/mysql-server:8'
        ports:
          - '3306:3306'
        environment:
          MYSQL_ROOT_PASSWORD: "password"
          MYSQL_ROOT_HOST: "%"
          MYSQL_DATABASE: "kj"
          MYSQL_USER: "kj"
          MYSQL_PASSWORD: "kj"
          MYSQL_ALLOW_EMPTY_PASSWORD: 1
        volumes:
          - './storage/docker/mysql/:/var/lib/mysql'
        networks:
          - local-proxy-network
        restart: always

这个是 MySQL 升级至 8 后有修改密码验证方式导致的问题

版本 验证方式
MySQL 8 caching_sha2_password
MySQL 5.7 mysql_native_password

解决方式 1:修改连线方式

使用 Terminal 连线到 MySQL 后将连线方式修改为 mysql_native_password

ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'your-password';

解决方式 2:修改 my.cnf 设定档案

编辑 MySQL 8 的 my.cnf 档案

vim my.cnf

设定预设密码验证方式为 mysql_native_password

[mysqld]
default_authentication_plugin=mysql_native_password

Reference

comments powered by Disqus
All rights reserved,未經允許不得隨意轉載
Built with Hugo
主题 StackJimmy 设计