目次

1. はじめに

Important Change: The deprecated mysql_native_password authentication plugin is now disabled by default. It can be enabled by starting MySQL with the new –mysql-native-password=ON server option, or by adding mysql_native_password=ON to the [mysqld] section of your MySQL configuration file.

2. これまでの mysql_native_password 認証プラグイン

The mysql_native_password authentication plugin now is deprecated and subject to removal in a future version of MySQL. CREATE USER, ALTER USER, and SET PASSWORD operations now insert a deprecation warning into the server error log if an account attempts to authenticate using mysql_native_password as an authentication method. (Bug #35336317)

The mysql_native_password plugin, which was deprecated previously, now is no longer mandatory and can be disabled at server startup. For information about this plugin, see Native Pluggable Authentication. For general information about pluggable authentication and other available authentication plugins, see Pluggable Authentication and Authentication Plugins.

3. MySQL8.4での確認

				
					mysql> CREATE USER user01 IDENTIFIED WITH mysql_native_password BY 'MySQL8.4';
ERROR 1524 (HY000): Plugin 'mysql_native_password' is not loaded
				
			

プラグインを確認すると、Status が DISABLED になっています。

				
					mysql> SHOW PLUGINS;
+----------------------------------+----------+--------------------+---------+---------+
| Name                             | Status   | Type               | Library | License |
+----------------------------------+----------+--------------------+---------+---------+
(省略)
| mysql_native_password            | DISABLED | AUTHENTICATION     | NULL    | GPL     |
+----------------------------------+----------+--------------------+---------+---------+
				
			
				
					authentication_policy=mysql_native_password,,
				
			

以下のようにエラーで起動することができません。

				
					# systemctl start mysqld Job for mysqld.service failed because the control process exited with error code. See "systemctl status mysqld.service" and "journalctl -xe" for details. # tail -f /var/log/mysqld.log (省略) 2024-05-14T09:55:11.459216Z 0 [ERROR] [MY-013797] [Server] Option --authentication-policy is set to an invalid value. Please check if the specified authentication plugins are valid.
				
			
				
					mysql_native_password=on
				
			

設定後、サービスを再起動してプラグインを確認すると、Status が ACTIVE になっています。

				
					# systemctl restart mysqld
# mysql
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 9
Server version: 8.4.0 MySQL Community Server - GPL

Copyright (c) 2000, 2024, Oracle and/or its affiliates.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> SHOW PLUGINS;
+----------------------------------+----------+--------------------+---------+---------+
| Name                             | Status   | Type               | Library | License |
+----------------------------------+----------+--------------------+---------+---------+
(省略)
| mysql_native_password            | ACTIVE   | AUTHENTICATION     | NULL    | GPL     |
+----------------------------------+----------+--------------------+---------+---------+
				
			

この状態になると、mysql_native_password を使用することが可能となります。

				
					mysql> CREATE USER user01 IDENTIFIED WITH mysql_native_password BY 'MySQL8.4';
Query OK, 0 rows affected (0.01 sec)

mysql> SELECT user, host, plugin FROM mysql.user WHERE user='user01';
+--------+------+-----------------------+
| user   | host | plugin                |
+--------+------+-----------------------+
| user01 | %    | mysql_native_password |
+--------+------+-----------------------+
1 row in set (0.00 sec)

				
			

また、mysql_native_password=on を設定することで、先程設定した authentication_policy での mysql_native_password の指定も行えるようになります。

				
					mysql_native_password=on
authentication_policy=mysql_native_password,,
				
			

サービス再起動後、 mysql_native_password のユーザが作成されるようになっています。

				
					mysql> CREATE USER user02 IDENTIFIED BY 'MySQL8.4';
Query OK, 0 rows affected (0.01 sec)

mysql> SELECT user, host, plugin FROM mysql.user WHERE user='user02';
+--------+------+-----------------------+
| user   | host | plugin                |
+--------+------+-----------------------+
| user02 | %    | mysql_native_password |
+--------+------+-----------------------+
1 row in set (0.00 sec)
				
			

しかし、注意点としてmysql_native_password のユーザがログインする度に、以下のような警告ログが出力されます。

				
					しかし、注意点としてmysql_native_password のユーザがログインする度に、以下のような警告ログが出力されます。
				
			
				
					mysql_native_password=on
default_authentication_plugin=mysql_native_password
				
			

パラメータが存在しない旨のエラーメッセージが出力され、サービス起動エラーとなりました。

				
					# systemctl restart mysqld
Job for mysqld.service failed because the control process exited with error code.
See "systemctl status mysqld.service" and "journalctl -xe" for details.
# tail -f /var/log/mysqld.log
(省略)
2024-05-14T09:47:16.410266Z 0 [ERROR] [MY-000067] [Server] unknown variable 'default_authentication_plugin=mysql_native_password'.
2024-05-14T09:47:16.411001Z 0 [ERROR] [MY-010119] [Server] Aborting
2024-05-14T09:47:17.949813Z 0 [System] [MY-010910] [Server] /usr/sbin/mysqld: Shutdown complete (mysqld 8.4.0)  MySQL Community Server - GPL.
2024-05-14T09:47:17.949877Z 0 [System] [MY-015016] [Server] MySQL Server - end.
				
			

4. バージョンアップ時の既存ユーザ

				
					mysql> SELECT user, plugin FROM mysql.user WHERE user='user01';
+--------+-----------------------+
| user   | plugin                |
+--------+-----------------------+
| user01 | mysql_native_password |
+--------+-----------------------+
				
			

その後、インプレースアップグレード→サービス起動を行った後にログインしたところ、以下のようなエラーとなりました

				
					# mysql -u user01 -p
Enter password:
ERROR 1524 (HY000): Plugin 'mysql_native_password' is not loaded
				
			

5. 【資料ダウンロード】MySQL 8.0→8.4の変更点をまとめて確認する

6. まとめ

MySQL 8.4 への移行・認証方式変更で、判断に迷っていませんか?

以下に当てはまる場合、事前整理が必要です。

☑ 既存アプリが mysql_native_password 前提
☑ 古いドライバやライブラリを使っている
☑ 複数システム・複数環境で同時に移行が必要
☑ 影響範囲の洗い出しができていない
☑ 認証方式変更の判断基準が分からない

当てはまる場合は、事前に影響範囲を整理しておくことをおすすめします

※自社対応を前提とした進め方の整理・影響範囲の確認もご相談いただけます
(必要に応じて支援範囲をご提案します)