概要
ユーザーの認証プラグインをデフォルトのcaching_sha2_password からmysql_native_passwordに変更しようとしたらエラーになったのでその対処方法の備忘録。
環境
MySQLバージョン: 8.0.30 MySQL Community Server - GPL
OS: Windows11
手順
対象のユーザー
mysql> select user, host, plugin from user where user = 'admin';
+------------------+-----------+-----------------------+
| user | host | plugin |
+------------------+-----------+-----------------------+
| admin | % | caching_sha2_password |
+------------------+-----------+-----------------------+
1 row in set (0.00 sec)
このユーザーのpluginをmysql_native_passwordにしたい。
mysql> alter user 'admin'@'%' identified with mysql_native_password by 'Passw0rd';
ERROR 4058 (HY000): 1 factor authentication method does not match against authentication policy. Please refer @@authentication_policy system variable.
1要素の方式だとauthentication_policyに反しているみたいなことを言われる。
現在のauthentication_policyの値を確認。
mysql> show global variables like 'authentication_policy';
+-----------------------+-------------------------+
| Variable_name | Value |
+-----------------------+-------------------------+
| authentication_policy | caching_sha2_password,, |
+-----------------------+-------------------------+
1 row in set, 1 warning (0.00 sec)
この辺に値の設定の仕方が載っている。8.0.27から追加されたらしい。
https://dev.mysql.com/doc/refman/8.0/en/server-system-variables.html#sysvar_authentication_policy
寛容そうな設定に変更してみる。
mysql> set global authentication_policy = '*,,';
Query OK, 0 rows affected (0.00 sec)
mysql> show global variables like 'authentication_policy';
+-----------------------+-------+
| Variable_name | Value |
+-----------------------+-------+
| authentication_policy | *,, |
+-----------------------+-------+
1 row in set, 1 warning (0.00 sec)
変更できた。
再度ユーザー変更に挑戦。
mysql> alter user 'admin'@'%' identified with mysql_native_password by 'Passw0rd';
Query OK, 0 rows affected (0.00 sec)
mysql> select user, host, plugin from user where user = 'admin';
+-------+------+-----------------------+
| user | host | plugin |
+-------+------+-----------------------+
| admin | % | mysql_native_password |
+-------+------+-----------------------+
1 row in set (0.00 sec)
できた。