LoginSignup
89
65

More than 5 years have passed since last update.

Docker で MySQL 8.0.4 を使う

Last updated at Posted at 2018-04-15

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)

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

89
65
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
89
65