Featured image of post Solved MySQL 8 Docker Unable Login Issue: Authentication plugin 'caching_sha2_password' cannot be loaded

Solved MySQL 8 Docker Unable Login Issue: Authentication plugin 'caching_sha2_password' cannot be loaded

Solved MySQL 8 Docker Unable Login Issue: Authentication plugin 'caching_sha2_password' cannot be loaded

Root cause

After install the MySQL 8 (mysql/mysql-server:8) via docker-compose. And it shows the following failure messages while I login

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

This issue is that the MySQL change their default authentication method after upgrade to the 8.x version

Version Default authentication method
MySQL 8 caching_sha2_password
MySQL 5.7 mysql_native_password

Solution 1: SQL

Login to the MySQL via terminal and paste the following command to alter the default authentication method to mysql_native_password

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

Solution 2: my.cnf

Edit the my.cnf file from MySQL 8

vim my.cnf

Setting the default authentication to mysql_native_password

[mysqld]
default_authentication_plugin=mysql_native_password

Reference

comments powered by Disqus
All rights reserved,未經允許不得隨意轉載
Built with Hugo
Theme Stack designed by Jimmy