参考

  • https://dev.mysql.com/doc/refman/8.0/ja/authentication-plugins.html
  • https://blog.s-style.co.jp/2024/05/11793/#index_id2

認証プラグイン

デフォルトの認証プラグイン:caching_sha2_password

認証プラグインを変更

認証プラグインを mysql_native_password に変更する例を記載します。

  1. 全体の認証プラグインを変更( cnf ファイルで指定 )
  2. 個別ユーザーの認証プラグインを変更( alter table )

全体の認証プラグインを変更(MySQL 8.0.26以前)

⚠️ 注意(バージョン依存)
default_authentication_pluginMySQL 8.0.27 で非推奨となり、MySQL 8.4.0 で完全に削除されました。8.4 以降は authentication_policy システム変数を使用してください(default_authentication_plugin を cnf に書いても無視されます)。また 8.4 以降は mysql_native_password プラグイン自体もデフォルトで無効化されています。以下の手順は 8.0.26 以前を対象としています。

ref. https://dev.mysql.com/doc/mysqld-version-reference/en/optvar-changes-8-4.html

cnf ファイルで認証方式を指定します( cnf ファイルは複数存在する場合がありますが /etc/my.cnf と仮定します)。

[mysqld]
default_authentication_plugin=mysql_native_password

変更されたことを確認します。

mysql> show variables like 'default_authentication_plugin';
 
<出力結果>
+-------------------------------+-----------------------+
| Variable_name                 | Value                 |
+-------------------------------+-----------------------+
| default_authentication_plugin | mysql_native_password |
+-------------------------------+-----------------------+

個別ユーザーの認証方式を変更

ユーザーの認証方式を変更します。

mysql > alter user 'example'@'localhost' identified with mysql_native_password BY 'password';

変更されたことを確認します。

mysql> select host, user, plugin from mysql.user;
+-----------+------------------+-----------------------+
| host      | user             | plugin                |
+-----------+------------------+-----------------------+
| ...       | ...              | ...                   |
| localhost | example          | mysql_native_password |
| ...       | ...              | ...                   |
+-----------+------------------+---------

備考

パスワードポリシー

mysql> show variables like '%validate_password%';
+-------------------------------------------------+-------+
| Variable_name                                   | Value |
+-------------------------------------------------+-------+
| validate_password.changed_characters_percentage | 0     |
| validate_password.check_user_name               | ON    |
| validate_password.dictionary_file               |       |
| validate_password.length                        | 8     |
| validate_password.mixed_case_count              | 1     |
| validate_password.number_count                  | 1     |
| validate_password.policy                        | LOW   |
| validate_password.special_char_count            | 1     |
+-------------------------------------------------+-------+

ref. https://qiita.com/keisukeYamagishi/items/d897e5c52fe9fd8d9273

ルートパスワード設定

// パスワードを再設定
mysql > use mysql;
mysql > alter user 'root'@'localhost' identified by 'password';

root スワードをリセット

root パスワードをリセット