LoginSignup
1
2

More than 3 years have passed since last update.

MySQL8.0.17の認証プラグインを変更する

Posted at

Laravelで下記のエラーが発生した場合

PDOException::("PDO::__construct(): The server requested authentication method unknown to the client [caching_sha2_password]")

システム変数 default_authentication_plugin の値を表示します

mysql> SHOW VARIABLES LIKE 'default_authentication_plugin';
+-------------------------------+-----------------------+
| Variable_name                 | Value                 |
+-------------------------------+-----------------------+
| default_authentication_plugin | caching_sha2_password |
+-------------------------------+-----------------------+
1 row in set (0.02 sec)

rootユーザーの認証プラグインをmysql_native_passwordに変更する

mysql> ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'pass';
Query OK, 0 rows affected (0.01 sec)

接続を終了する

mysql> exit;
Bye

再起動する

<コンピューター名>-no-MBP:~ <ユーザー名>$ mysql.server restart;
Shutting down MySQL
.. SUCCESS! 
Starting MySQL
. SUCCESS! 

再度起動して接続する

<コンピューター名>-no-MBP:~ <ユーザー名>$ mysql -u root -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 8.0.17 Homebrew

mysql.user テーブルからuser, host, pluginのカラムの値を表示する

rootユーザーのpluginの値がmysql_native_passwordになっている

mysql>  SELECT user, host, plugin FROM mysql.user;
+------------------+-----------+-----------------------+
| user             | host      | plugin                |
+------------------+-----------+-----------------------+
| mysql.infoschema | localhost | caching_sha2_password |
| mysql.session    | localhost | caching_sha2_password |
| mysql.sys        | localhost | caching_sha2_password |
| root             | localhost | mysql_native_password |
+------------------+-----------+-----------------------+
4 rows in set (0.00 sec)

参考

https://qiita.com/ucan-lab/items/3ae911b7e13287a5b917
https://dev.mysql.com/doc/refman/5.6/ja/show-variables.html
https://www.dbonline.jp/mysql/user/index9.html

1
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
2