Sửa lỗi java.sql.SQLException: Unable to load authentication plugin ‘caching_sha2_password’.

Sửa lỗi java.sql.SQLException: Unable to load authentication plugin ‘caching_sha2_password’.

Lỗijava.sql.SQLException: Unable to load authentication plugin 'caching_sha2_password' là do từ MySQL 8.0 caching_sha2_password được sử dụng làm plugin authentication mặc định thay cho mysql_native_password

Do đó bạn thường gặp lỗi này khi update MySQL server lên 8.0

Solution – Giải pháp

Cách 1: Thay đổi mã hóa mật khẩu của user bằng cách chạy lệnh dưới đây:

ALTER USER 'username'@'ip_address' IDENTIFIED WITH mysql_native_password BY 'password';

Ví dụ trường hợp của mình là:

ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'admin1234';

Sửa lỗi java.sql.SQLException: Unable to load authentication plugin 'caching_sha2_password'.

Cách 2: Chuyển plugin authentication mặc định về mysql_native_password

Sửa file option của MySQL: file my.cnf trên linux hoặc file my.ini trên Windows:

default_authentication_plugin=mysql_native_password

Hoặc sửa trực tiếp trên MySQL Workbench

Sửa lỗi java.sql.SQLException: Unable to load authentication plugin 'caching_sha2_password'

Sau đó restart lại MySQL Server.

Sửa lỗi java.sql.SQLException: Unable to load authentication plugin ‘caching_sha2_password’. stackjava.com

Okay, Done!

References:

https://dev.mysql.com/…/caching-sha2-pluggable-authentication.html

https://stackoverflow.com/…caching-sha2-password-cannot-be-loaded

stackjava.com