概要
MySQL8.0
をインストール後、Sequel Pro
でログインしようと思ったら、認証ができずにハマったので、その解決方法を自分の備忘録として残しています。
対象
-
主な対象
-
MySQL8.0
をインストールした方 -
Sequel Pro
を利用する方
-
-
対象(以下の方にも役に立つと思います)
- 他のGUIツールを使用して
MySQL
にログインする方 -
Docker
等でMySQLサーバを構築する方
- 他のGUIツールを使用して
前提(環境とか)
- macOS :
High Sierra 10.13.6
- MySQL :
8.0.12
- MySQLのユーザ :
yoshio
Sequel Pro
Sequel Proにて接続
まずはiTermからアクセスできることを確認します。
❯ mysql -u yoshio -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 15
Server version: 8.0.12 Homebrew
Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.
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>
では、Sequel Pro
でアクセスします。
ホスト名とユーザ名、パスワードを入力し、接続をテスト
をクリックします。
エラーメッセージを読みます。
MySQL の応答: Authentication plugin 'caching_sha2_password' cannot be loaded: dlopen(/usr/local/lib/plugin/caching_sha2_password.so, 2): image not found
どうやらcaching_sha2_password
が原因なようです。
公式ドキュメントを読む
迷った時は公式ドキュメントを読みます。
ざっくり抜粋して、ざっくり要約します。 ( 参照 : MySQLの公式ドキュメント )
抜粋
The caching_sha2_password and sha256_password authentication plugins provide more secure password encryption than the mysql_native_password plugin, and caching_sha2_password provides better performance than sha256_password. Due to these superior security and performance characteristics of caching_sha2_password, it is as of MySQL 8.0 the preferred authentication plugin, and is also the default authentication plugin rather than mysql_native_password.`
要約
-
caching_sha2_password
は、MySQLの認証プラグインである。 - 昔の認証プラグインのデフォルト:
mysql_native_password
- 今の認証プラグインのデフォルト:
caching_sha2_password
- デフォルトのプラグインが変わったのは、
安全性の強化
。
問題点
- アプリ側が対応していないといけない点 (Sequel Proに限らない)
解決策
- 標準ターミナルやiTermで頑張る。
- アプリ側の
caching_sha2_password
への対応を待つ。 -
Sequel Pro
にログインするユーザの認証プラグインを変更する。
認証プラグインの変更
前述の解決策「3」を実行します。
iTermを開いてMySQL
にログインします。
❯ mysql -u yoshio -p
ログイン後、以下のコマンドにて使用したいユーザの認証プラグイン
を確認します。
mysql> SELECT host, user, plugin FROM mysql.user;
+-----------+------------------+-----------------------+
| host | user | plugin |
+-----------+------------------+-----------------------+
| localhost | yoshio | caching_sha2_password |
+-----------+------------------+-----------------------+
caching_sha2_password
を mysql_native_password
に変更します。
mysql> ALTER USER 'yoshio'@"localhost" IDENTIFIED WITH mysql_native_password BY '{password}';
もう一度確認して、次のようになっていることを確認してください。
これでyoshio
の認証プラグインが作成されました。
mysql> SELECT host, user, plugin FROM mysql.user;
+-----------+------------------+-----------------------+
| host | user | plugin |
+-----------+------------------+-----------------------+
| localhost | yoshio | mysql_native_password |
+-----------+------------------+-----------------------+
最後に、設定を反映します。
mysql> FLUSH PRIVILEGES;
再び、Sequel Proにて接続
再び、Sequel Pro
でアクセスします。
ホスト名とユーザ名、パスワードを入力し、接続をテスト
をクリックします。
接続が成功しました
が表示されることを確認してください。
デフォルトの認証プラグイン
前述の認証プラグインの変更では、ユーザごとに認証プラグインを変更していましたが、デフォルトの認証プラグインを変えたい場合は、my.cnf
に以下を追記してください。( 参照 : my.cnfの設定 )
[mysqld]
default_authentication_plugin=mysql_native_password
まとめ
- 外部ツールにて
MySQL8.0
へログインできないときは認証プラグインの設定を疑うといいかもしれません。 - 安全性はもちろん下がります。
-
yoshio
は仮名なので、実際の人物とは一切関係ありません。 - Qiita初投稿です。