Help us understand the problem. What is going on with this article?

Docker で MySQL 8.0.4 を使う

More than 1 year has passed since last update.

docker 上の Rails に mysql:8.0.4 を使おうとして mysql 認証にはまったのでその対応記録

結論

caching_sha2_password の認証形式に対応できないので
下記のカスタム設定をマウントして認証形式を変更する

[mysqld]
default_authentication_plugin= mysql_native_password

mysql8.0

Mysql8.0 ではデフォルトの認証形式を mysql_native_password から caching_sha2_password に変更している。
https://dev.mysql.com/doc/refman/8.0/en/caching-sha2-pluggable-authentication.html

起きたこと

rake db:create で下記エラー

Mysql2::Error (Authentication plugin 'caching_sha2_password' cannot be loaded: /usr/lib/x86_64-linux-gnu/mariadb18/plugin/caching_sha2_password.so: cannot open shared object file: No such file or directory):

caching_sha2_password に対応させる方法までは調べられなかったので mysql_native_password に設定を変更する方向に。

対応

設定ファイル

下記設定ファイルをローカルに作成

mysql-confd/default_authentication.cnf
[mysqld]
default_authentication_plugin= mysql_native_password

マウント

Docker の Mysql は /etc/mysql/conf.d/*.cnf を読み込むようなのでマウントを設定

docker-comnpose.yml
  mysql:
    image: "mysql:8.0.4"
    # ...
    volumes:
      - ./mysql-confd:/etc/mysql/conf.d

再起動

コンテナ、ボリュームを一旦削除して再起動

MySQL > SELECT user, host, plugin FROM mysql.user;
+------------------+-----------+-----------------------+
| user             | host      | plugin                |
+------------------+-----------+-----------------------+
| root             | %         | mysql_native_password |
| mysql.infoschema | localhost | mysql_native_password |
| mysql.session    | localhost | mysql_native_password |
| mysql.sys        | localhost | mysql_native_password |
| root             | localhost | mysql_native_password |
+------------------+-----------+-----------------------+
5 rows in set (0.00 sec)

これで問題なく認証が通るようになった

yensaki
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした