それが僕には楽しかったんです。

僕と MySQL と時々 MariaDB

MySQL の docker コンテナを起動した時の warning, error を調べつくす

はじめに

ふと MySQL の docker コンテナのログを見たら、なにやら warning や error を吐いていたから原因を調べてみた。
基本的な設定は password 周りと port 33060, MYSQL_ROOT_PASSWORD のみ設定している

問題のログ

master_1  | 2020-05-24 14:14:47+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.18-1debian9 started.
master_1  | 2020-05-24 14:14:47+00:00 [Note] [Entrypoint]: Switching to dedicated user 'mysql'
master_1  | 2020-05-24 14:14:47+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.18-1debian9 started.
master_1  | 2020-05-24 14:14:47+00:00 [Note] [Entrypoint]: Initializing database files
master_1  | 2020-05-24T14:14:47.489542Z 0 [Warning] [MY-011070] [Server] 'Disabling symbolic links using --skip-symbolic-links (or equivalent) is the default. Consider not using this option as it' is deprecated and will be removed in a future release.
master_1  | 2020-05-24T14:14:47.490218Z 0 [System] [MY-013169] [Server] /usr/sbin/mysqld (mysqld 8.0.18) initializing of server in progress as process 48
master_1  | 2020-05-24T14:14:51.079329Z 5 [Warning] [MY-010453] [Server] root@localhost is created with an empty password ! Please consider switching off the --initialize-insecure option.
master_1  | 2020-05-24 14:14:54+00:00 [Note] [Entrypoint]: Database files initialized
master_1  | 2020-05-24 14:14:54+00:00 [Note] [Entrypoint]: Starting temporary server
master_1  | 2020-05-24T14:14:54.738243Z 0 [Warning] [MY-011070] [Server] 'Disabling symbolic links using --skip-symbolic-links (or equivalent) is the default. Consider not using this option as it' is deprecated and will be removed in a future release.
master_1  | 2020-05-24T14:14:54.739005Z 0 [System] [MY-010116] [Server] /usr/sbin/mysqld (mysqld 8.0.18) starting as process 97
master_1  | 2020-05-24T14:14:55.555469Z 0 [Warning] [MY-010068] [Server] CA certificate ca.pem is self signed.
master_1  | 2020-05-24T14:14:55.566293Z 0 [Warning] [MY-011810] [Server] Insecure configuration for --pid-file: Location '/var/run/mysqld' in the path is accessible to all OS users. Consider choosing a different directory.
master_1  | 2020-05-24T14:14:55.608994Z 0 [System] [MY-010931] [Server] /usr/sbin/mysqld: ready for connections. Version: '8.0.18'  socket: '/var/run/mysqld/mysqld.sock'  port: 0  MySQL Community Server - GPL.
master_1  | 2020-05-24 14:14:55+00:00 [Note] [Entrypoint]: Temporary server started.
master_1  | 2020-05-24T14:14:55.863681Z 0 [System] [MY-011323] [Server] X Plugin ready for connections. Socket: '/var/run/mysqld/mysqlx.sock'
master_1  | Warning: Unable to load '/usr/share/zoneinfo/iso3166.tab' as time zone. Skipping it.
master_1  | Warning: Unable to load '/usr/share/zoneinfo/leap-seconds.list' as time zone. Skipping it.
master_1  | Warning: Unable to load '/usr/share/zoneinfo/zone.tab' as time zone. Skipping it.
master_1  | Warning: Unable to load '/usr/share/zoneinfo/zone1970.tab' as time zone. Skipping it.
master_1  | 2020-05-24 14:14:59+00:00 [Note] [Entrypoint]: Creating database sample
master_1  | 
master_1  | 2020-05-24 14:14:59+00:00 [Note] [Entrypoint]: Stopping temporary server
master_1  | 2020-05-24T14:14:59.745593Z 11 [System] [MY-013172] [Server] Received SHUTDOWN from user root. Shutting down mysqld (Version: 8.0.18).
master_1  | 2020-05-24T14:15:00.689149Z 0 [System] [MY-010910] [Server] /usr/sbin/mysqld: Shutdown complete (mysqld 8.0.18)  MySQL Community Server - GPL.
master_1  | 2020-05-24 14:15:00+00:00 [Note] [Entrypoint]: Temporary server stopped
master_1  | 
master_1  | 2020-05-24 14:15:00+00:00 [Note] [Entrypoint]: MySQL init process done. Ready for start up.
master_1  | 
master_1  | 2020-05-24T14:15:01.036210Z 0 [Warning] [MY-011070] [Server] 'Disabling symbolic links using --skip-symbolic-links (or equivalent) is the default. Consider not using this option as it' is deprecated and will be removed in a future release.
master_1  | 2020-05-24T14:15:01.036868Z 0 [System] [MY-010116] [Server] /usr/sbin/mysqld (mysqld 8.0.18) starting as process 1
master_1  | 2020-05-24T14:15:01.733035Z 0 [Warning] [MY-010068] [Server] CA certificate ca.pem is self signed.
master_1  | 2020-05-24T14:15:01.743247Z 0 [Warning] [MY-011810] [Server] Insecure configuration for --pid-file: Location '/var/run/mysqld' in the path is accessible to all OS users. Consider choosing a different directory.
master_1  | 2020-05-24T14:15:01.783752Z 0 [System] [MY-010931] [Server] /usr/sbin/mysqld: ready for connections. Version: '8.0.18'  socket: '/var/run/mysqld/mysqld.sock'  port: 33060  MySQL Community Server - GPL.
master_1  | 2020-05-24T14:15:02.882639Z 0 [ERROR] [MY-011300] [Server] Plugin mysqlx reported: 'Setup of bind-address: '*' port: 33060 failed, `bind()` failed with error: Address already in use (98). Do you already have another mysqld server running with Mysqlx ?'
master_1  | 2020-05-24T14:15:02.882761Z 0 [System] [MY-011323] [Server] X Plugin ready for connections. Socket: '/var/run/mysqld/mysqlx.sock' 

symbolic-links=0 が元のコンテナイメージ側にある Dockerfile で設定されているために発生するエラー。
おそらく MySQL 8.0.2 以降で非推奨になっている?
dev.mysql.com

あと、デフォルトで無効化されているため設定する必要がない。
dev.mysql.com

これはプルリクだした。マージされてないが LGTM が帰ってきている。
github.com


[Warning] [MY-010453] [Server] root@localhost is created with an empty password ! Please consider switching off the --initialize-insecure option.

起動時に datadir/mysql が存在しなければ、--initialize-insecure が無条件でつけられる。それで、このオプションをつけると必ず発生するのがこの Warning。
パスワードなしで root が生成されるが、その後にパスワードが設定されることが想定される場合はやっているみたい。
dev.mysql.com

実際 entrypoint.sh で --initialize-insecure 付きで実行された後に root アカウントに対してなにやらパスワードが設定されている部分を見つけた。
github.com

[Warning] [MY-010068] [Server] CA certificate ca.pem is self signed.

MySQL 8 で auto_generate_certs が有効になっている場合(デフォルトで有効になっている) datadir に証明書がなければ自己署名証明書が生成される。
証明書が自己署名である場合にこのエラーは発生する。

[Warning] [MY-011810] [Server] Insecure configuration for --pid-file: Location '/var/run/mysqld' in the path is accessible to all OS users. Consider choosing a different directory.

これは権限周りがあれしてあれになっている。
MySQL 8.0.18 の docker コンテナを割と最小構成で起動した時のログ。default_native_password, port=33060, MYSQL_ROOT_PASSWORD だけ設定している · GitHub

詳しくは yoku さんが解説していて pid ファイルそのものや pid ファイルを置いているディレクトリが o+w になっていると発生するエラーらしい。

Warning: Unable to load '/usr/share/zoneinfo/iso3166.tab' as time zone. Skipping it.

これはタイムゾーンのロードしている部分なのだが、 zoneinfo を全て見ているっぽくて timezone data 以外のファイルをロードしようとするとこの手のエラーを吐く。

[ERROR] [MY-011300] [Server] Plugin mysqlx reported: 'Setup of bind-address: '*' port: 33060 failed, `bind()` failed with error: Address already in use (98). Do you already have another mysqld server running with Mysqlx ?'

MySQL 側の port を 33060 にしているため mysqlx のものとかぶってしまっているために発生しているエラー。

おわりに

プルリク一個出せたので満足。