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

时间:2018-05-18 20:59:43

标签: mysql docker init flyway

我正在使用mysql docker容器并在docker-entrypoint-initdb.d中添加了一个init脚本,如下所述: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)

1 个答案:

答案 0 :(得分:3)

似乎在调用initdb脚本时,MySQL只能通过套接字而不是通过网络连接获得。因此,飞路无法运行。我现在正在使用flyway的第二个docker容器连接到MySQL容器。这很好。