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



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

jfabianmeier@JFM-HP-2018:~$ sshpass -p mySuperPassword ssh -o StrictHostKeyChecking=no -M -S my-ctrl-socket -fNT -L 3306:mysql5:3306 myUserName@alfa3031.alfahosting-server.de
jfabianmeier@JFM-HP-2018:~$ ssh -S my-ctrl-socket -O check myUserName@alfa3031.alfahosting-server.de
Master running (pid=405)

连接MySQL似乎可以工作,至少在没有SSL的情况下是这样(我不知道为什么,也许服务器只支持旧协议(。

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问题有关。老实说,我不理解错误消息,也没能通过谷歌找到有用的东西。

如果您能够连接到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图片文档在描述如何提供必要的更改日志时提到了以下内容:

docker映像有一个/liquibase/changelog卷,其中的目录可以挂载包含变更日志树的根。你的-- changeLogFile参数应列出与此相关的路径。

根据该建议,请尝试提供以下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

相关内容

  • 没有找到相关文章

最新更新