mysql8 デフォルト認証方式「caching_sha2_password」を変更する

mysql8よりデフォルトの認証方式となった「caching_sha2_password」を「mysql_native_password」に変更する手順を記述してます。
環境
- OS ubuntu 20.04.1
- mysql 8.0.21
my.cnfパス確認
デフォルトの認証方式を変更するため、まずmy.cnfのパスを検索します。
パス場所は「mysql –help」の中に読み込み順番が記述されています。
1 2 3 4 5 |
mysql --help | grep my.cnf <出力結果> order of preference, my.cnf, $MYSQL_TCP_PORT, /etc/my.cnf /etc/mysql/my.cnf ~/.my.cnf |
順番に存在するか確認してみます。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
$ sudo cat /etc/my.cnf <出力結果> cat: /etc/my.cnf: そのようなファイルやディレクトリはありません $ sudo cat /etc/mysql/my.cnf <出力結果> # # The MySQL database server configuration file. # # You can copy this to one of: # - "/etc/mysql/my.cnf" to set global options, # - "~/.my.cnf" to set user-specific options. # # One can use all long options that the program supports. # Run program with --help to get a list of available options and with # --print-defaults to see which it would actually understand and use. # # For explanations see # http://dev.mysql.com/doc/mysql/en/server-system-variables.html # # * IMPORTANT: Additional settings that can override those from this file! # The files must end with '.cnf', otherwise they'll be ignored. # !includedir /etc/mysql/conf.d/ !includedir /etc/mysql/mysql.conf.d/ |
/etc/mysql/my.cnfに存在することが確認できました。
デフォルト認証方式変更
my.cnfを確認すると以下がincludeされているので、
1 |
!includedir /etc/mysql/mysql.conf.d/ |
「/etc/mysql/mysql.conf.d/」に移動して、設定ファイルを変更します。
1 |
cd /etc/mysql/mysql.conf.d/ |
編集するファイルは、以下となります。
1 |
sudo nano mysqld.cnf |
「mysqld.cnf」に以下を追加します。
1 |
default_authentication_plugin=mysql_native_password |
設定を反映させるためmysqlを再起動します。
1 |
sudo service mysql restart |
デフォルト認証方式確認
デフォルトの認証方式が変更されたかを確認してみます。
1 2 3 4 5 6 7 8 |
mysql> show variables like 'default_authentication_plugin'; <出力結果> +-------------------------------+-----------------------+ | Variable_name | Value | +-------------------------------+-----------------------+ | default_authentication_plugin | mysql_native_password | +-------------------------------+-----------------------+ |
認証方式が「mysql_native_password」に変更されていることが確認できます。
※mysql8でユーザーに権限を付与する方法はこちら
-
前の記事
mysql8 エラー「ERROR 1698 (28000): Access denied for user ‘root’@’localhost’」が発生した場合の対処法 2020.08.17
-
次の記事
javascript 画面の解像度とウィンドウサイズを取得する 2020.08.17
コメントを書く