docker mysql initdb脚本无法连接到数据库

yvfmudvl  于 2021-06-20  发布在  Mysql
关注(0)|答案(1)|浏览(558)

我用的是 mysql docker容器并将初始化脚本添加到 docker-entrypoint-initdb.d 如下所述:https://hub.docker.com/_/mysql/ (初始化新示例)。
init脚本应该使用flyway命令行工具来迁移数据库内容。我收到一个错误,flyway无法连接到数据库。为什么会这样?据我所知,数据库应该在那个时候启动并运行。

[...]
2018-05-18T20:52:45.558031Z 0 [Note] mysqld: ready for connections.
Version: '5.7.22'  socket: '/var/run/mysqld/mysqld.sock'  port: 0  MySQL Community Server (GPL)
Warning: Unable to load '/usr/share/zoneinfo/iso3166.tab' as time zone. Skipping it.
Warning: Unable to load '/usr/share/zoneinfo/leap-seconds.list' as time zone. Skipping it.
Warning: Unable to load '/usr/share/zoneinfo/zone.tab' as time zone. Skipping it.
Warning: Unable to load '/usr/share/zoneinfo/zone1970.tab' as time zone. Skipping it.
2018-05-18T20:52:50.940818Z 4 [Warning] 'user' entry 'root@localhost' ignored in --skip-name-resolve mode.
2018-05-18T20:52:50.940841Z 4 [Warning] 'user' entry 'mysql.session@localhost' ignored in --skip-name-resolve mode.
2018-05-18T20:52:50.940864Z 4 [Warning] 'user' entry 'mysql.sys@localhost' ignored in --skip-name-resolve mode.
2018-05-18T20:52:50.940881Z 4 [Warning] 'db' entry 'performance_schema mysql.session@localhost' ignored in --skip-name-resolve mode.
2018-05-18T20:52:50.940886Z 4 [Warning] 'db' entry 'sys mysql.sys@localhost' ignored in --skip-name-resolve mode.
2018-05-18T20:52:50.940897Z 4 [Warning] 'proxies_priv' entry '@ root@localhost' ignored in --skip-name-resolve mode.
2018-05-18T20:52:50.940926Z 4 [Warning] 'tables_priv' entry 'user mysql.session@localhost' ignored in --skip-name-resolve mode.
2018-05-18T20:52:50.940935Z 4 [Warning] 'tables_priv' entry 'sys_config mysql.sys@localhost' ignored in --skip-name-resolve mode.
mysql: [Warning] Using a password on the command line interface can be insecure.

/usr/local/bin/docker-entrypoint.sh: running /docker-entrypoint-initdb.d/migrate.sh
Flyway Community Edition 5.0.7 by Boxfuse

ERROR: 
Unable to obtain connection from database (jdbc:mysql://localhost/db) for user 'root': Could not connect to address=(host=localhost)(port=3306)(type=master) : Connection refused (Connection refused)
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
SQL State  : 08
Error Code : -1
Message    : Could not connect to address=(host=localhost)(port=3306)(type=master) : Connection refused (Connection refused)
sg24os4d

sg24os4d1#

似乎在 initdb 称为mysql的脚本只能通过socket使用,不能通过网络连接使用。因此,flyway无法运行。我现在为flyway使用第二个docker容器,它连接到mysql容器。这个很好用。

相关问题