mysql - 使用 Liquibase (Docker) 连接到 SSH 隧道数据库

标签 mysql docker ssl ssh liquibase

我构建了一个通往 MySQL 数据库的 SSH 隧道(我知道这可以在没有密码的情况下完成,但这不是问题)。

jfabianmeier@JFM-HP-2018:~$ sshpass -p mySuperPassword ssh -o StrictHostKeyChecking=no -M -S my-ctrl-socket -fNT -L 3306:mysql5:3306 <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="e98490bc9a8c9ba788848ca988858f88dad9dad8c788858f8881869a9d80878ec49a8c9b9f8c9bc78d8c" rel="noreferrer noopener nofollow">[email protected]</a>
jfabianmeier@JFM-HP-2018:~$ ssh -S my-ctrl-socket -O check myU<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="dcafb9ae92bdb1b99cbdb0babdefecefedf2bdb0babdb4b3afa8b5b2bbf1afb9aeaab9aef2b8b9" rel="noreferrer noopener nofollow">[email protected]</a>
Master running (pid=405)

连接到 MySQL 似乎可以工作,至少不需要 SSL(我不知道为什么,也许服务器只支持旧协议(protocol))。

jfabianmeier@JFM-HP-2018:~$ mysql -h 127.0.0.1 -P 3306 -u web1444 -pmyDBPassword --ssl-mode=DISABLED
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 140637890
Server version: 5.7.25 MySQL Community Server (GPL)

Copyright (c) 2000, 2022, Oracle and/or its affiliates.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> SHOW DATABASES;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| usr_web1444_1      |
| usr_web1444_2      |
| usr_web1444_3      |
| usr_web1444_4      |
| usr_web1444_5      |
+--------------------+
6 rows in set (0.26 sec)

mysql> exit
Bye

但是 Liquibase 不起作用。我尝试了下面的 Docker 命令,但无法弄清楚它出了什么问题。

jfabianmeier@JFM-HP-2018:~$ docker run -e INSTALL_MYSQL=true --rm -v $(pwd):$(pwd) liquibase/liquibase:4.15 --url=jdbc:mysql://localhost:3306/usr_web1444_4?autoReconnect=true&useSSL=false --changeLogFile=~/changelogs/changelog.sql --username=web144 --password=myDBPassword update
[1] 408
-bash: --changeLogFile=~/changelogs/changelog.sql: No such file or directory
jfabianmeier@JFM-HP-2018:~$ Checksum verified. Installing mysql-connector-java-8.0.30.jar to /liquibase/lib/
mysql-connector-java-8.0.30.jar successfully installed in classpath.
####################################################
##   _     _             _ _                      ##
##  | |   (_)           (_) |                     ##
##  | |    _  __ _ _   _ _| |__   __ _ ___  ___   ##
##  | |   | |/ _` | | | | | '_ \ / _` / __|/ _ \  ##
##  | |___| | (_| | |_| | | |_) | (_| \__ \  __/  ##
##  \_____/_|\__, |\__,_|_|_.__/ \__,_|___/\___|  ##
##              | |                               ##
##              |_|                               ##
##                                                ##
##  Get documentation at docs.liquibase.com       ##
##  Get certified courses at learn.liquibase.com  ##
##  Free schema change activity reports at        ##
##      https://hub.liquibase.com                 ##
##                                                ##
####################################################
Starting Liquibase at 09:56:38 (version 4.15.0 #4001 built at 2022-08-05 16:17+0000)
Liquibase Version: 4.15.0
Liquibase Community 4.15.0 by Liquibase
Missing required subcommand
Usage: liquibase [GLOBAL OPTIONS] [COMMAND] [COMMAND OPTIONS]
Command-specific help: "liquibase <command-name> --help"

Global Options
....

我想知道我的 Liquibase 命令是否错误,或者 URL 错误,或者问题是否可能与上述 SSL 问题有关。老实说,我不明白该错误消息,也无法通过 Google 找到有用的信息。

最佳答案

如果您能够连接 mysql 客户端,则可能隧道配置正确。

该错误似乎是因为 Liquibase 不理解从命令行调用 Docker 时提供的命令:

docker run -e INSTALL_MYSQL=true --rm -v $(pwd):$(pwd) liquibase/liquibase:4.15 --url=jdbc:mysql://localhost:3306/usr_web1444_4?autoReconnect=true&useSSL=false --changeLogFile=~/changelogs/changelog.sql --username=web144 --password=myDBPassword update

如您所见,它通过控制台打印错误和典型使用帮助:

Missing required subcommand
Usage: liquibase [GLOBAL OPTIONS] [COMMAND] [COMMAND OPTIONS]
Command-specific help: "liquibase <command-name> --help"

我测试了代码,它似乎是由 url 参数驱动的。

请尝试提供用引号引起来的值:

docker run -e INSTALL_MYSQL=true --rm -v $(pwd):$(pwd) liquibase/liquibase:4.15 --url="jdbc:mysql://localhost:3306/usr_web1444_4?autoReconnect=true&useSSL=false" --changeLogFile=~/changelogs/changelog.sql --username=web144 --password=myDBPassword update

此外,bash 报告 Liquibase 无法找到您的更改日志:

-bash: --changeLogFile=~/changelogs/changelog.sql: No such file or directory

Liquibase 官方 Docker 镜像 documentation在描述如何提供必要的更改日志时提到以下内容:

The docker image has a /liquibase/changelog volume in which the directory containing the root of your changelog tree can be mounted. Your -- changeLogFile argument should list paths relative to this.

按照该建议,请尝试提供以下 docker 命令来运行迁移(假设您的当前目录包含 changelogs/changelog.sql):

docker run -e INSTALL_MYSQL=true --rm -v $(pwd):/liquibase/changelog liquibase/liquibase:4.15 --url="jdbc:mysql://localhost:3306/usr_web1444_4?autoReconnect=true&useSSL=false" --changeLogFile=changelog/changelogs/changelog.sql --username=web144 --password=myDBPassword update

请再次注意使用双引号将 url 参数括起来。

如果您的隧道无法正常工作,Liquibase 将报告如下内容:

####################################################
##   _     _             _ _                      ##
##  | |   (_)           (_) |                     ##
##  | |    _  __ _ _   _ _| |__   __ _ ___  ___   ##
##  | |   | |/ _` | | | | | '_ \ / _` / __|/ _ \  ##
##  | |___| | (_| | |_| | | |_) | (_| \__ \  __/  ##
##  \_____/_|\__, |\__,_|_|_.__/ \__,_|___/\___|  ##
##              | |                               ##
##              |_|                               ##
##                                                ## 
##  Get documentation at docs.liquibase.com       ##
##  Get certified courses at learn.liquibase.com  ## 
##  Free schema change activity reports at        ##
##      https://hub.liquibase.com                 ##
##                                                ##
####################################################
Starting Liquibase at 17:22:56 (version 4.15.0 #4001 built at 2022-08-05 16:17+0000)
Liquibase Version: 4.15.0
Liquibase Community 4.15.0 by Liquibase

Unexpected error running Liquibase: Connection could not be created to jdbc:mysql://localhost:3306/usr_web1444_4?autoReconnect=true&useSSL=false with driver com.mysql.cj.jdbc.Driver.  Could not create connection to database server. Attempted reconnect 3 times. Giving up.
  - Caused by: Communications link failure

The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
  - Caused by: Connection refused

For more information, please use the --log-level flag

关于mysql - 使用 Liquibase (Docker) 连接到 SSH 隧道数据库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/73633631/

相关文章:

ruby-on-rails - Rails 不考虑 `DATABASE_URL` 环境中的 `test`?

docker - 如何运行拉取的图像-Docker

Dockerfile - 仅复制与扩展名匹配的文件,同时保持文件夹结构

api - 温室工作板 API 集成 : HTTP Basic Auth over SSL/TLS

python - 在代理后面使用 pip 安装任何包时出现 SSL 问题

mysql - 如何使用 Doctrine2 和 Symfony2 查看数据库模式更新的自动生成 SQL 查询?

mysql - 检查实例是否至少发生一次,每年在特定范围内

mysql - CodeIgniter - 当第二个表中没有行时 MySQL 连接

mysql - 如何以 Crystal 的方式从表中提取所需的数据?

Python Magic(智能,双模)SSL Socket?