Help us understand the problem. What is going on with this article?

FuelPHPでのMySQL接続時にThe server requested authentication method unknown to the client [caching_sha2_password] となった場合に対処してみた

概要

FuelPHPでMySQLに接続時、掲題のエラーが発生した場合の対応法です。

環境

  • MySQL v8.0
  • PHP 7.3.12

エラー事由

MySQL8.0でのデフォルトの認証方式は「caching_sha2_password」であるが、PHP側では対応がされていない。
そのため、認証方式が異なるためにエラ0が発生する。

対応方法

MySQLに接続するユーザーの認証方式を「mysql_native_password」に変更します。

1.ユーザー単位での認証方式の変更

先ず現状の認証方式を確認します。

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

現状を確認後、指定したユーザーの認証方式を変更します。

mysql> ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY 'password';
Query OK, 0 rows affected (0.19 sec)

2.デフォルトの認証方式の変更

MySQLへのデフォルトの認証方式を変更します。

/etc/mysql/conf.d/my.conf
[mysqld]
# デフォルトの認証方式を変更(デフォルトは「caching_sha2_password 」)
default-authentication-plugin=mysql_native_password
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした