MENU

MySQLでcaching_sha2_passwordが出たときの対処法

f:id:kiserukun:20210611090227p:plain

 
エクリプスでデータベースにデータを保存しようとするとエラーが出ました

java.sql.SQLException: Cannot create PoolableConnectionFactory (Unable to load authentication plugin 'caching_sha2_password'.)

caching_sha2_passwordとは

 
以前のMySQLでの認証プラグインにはmysql_native_password が使用されいましたが MySQL8.0より新たに caching_sha2_password に変更されました。  

Command Lineで確認

mysql> create user user1@localhost identified by 'パスワード';
Query OK, 0 rows affected (0.11 sec)
 
mysql> select User, Plugin from mysql.user where User = 'ユーザー名';
+-------+-----------------------+
| User | Plugin |
+-------+-----------------------+
| ユーザー名 | caching_sha2_password |
+-------+-----------------------+
1 row in set (0.00 sec) 

caching_sha2_password が設定されている事が確認できます。

対処法

Command Lineで以下のコマンドを実行します。

mysql> ALTER USER 'ユーザー名'@'localhost' IDENTIFIED WITH mysql_native_password BY 'パスワード';

 
 
以上です!
   

参考

MySQL8.0 認証方式を変更する(Laravel5) - Qiita  
 

MySQLリファレンス
https://dev.mysql.com/doc/refman/8.0/en/upgrading-from-previous-series.html#upgrade-caching-sha2-password-compatible-connectors MySQL :: MySQL 8.0 Reference Manual :: 2.11.4 Changes in MySQL 8.0