gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-29 05:04:51 25 4
gpt4 key购买 nike

我正在使用 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)

最佳答案

看来 initdb 脚本被称为 MySQL 只能通过套接字使用,不能通过网络连接使用。因此 flyway 无法运行。我现在正在使用第二个 docker 容器作为 flyway,它连接到 MySQL 容器。这很好用。

关于mysql - docker mysql initdb 脚本无法连接到数据库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50419202/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com