【发布时间】:2019-01-30 03:39:34
【问题描述】:
我目前正在评估 Liquibase 作为数据库版本控制解决方案。我在 Java 版本“1.8.0_181”的 Ubuntu 16.04 LTS 上运行。我已经安装了 Liquibase 3.6.2,我已经在端口 4408 和 4409 上设置了两个 MySQL 5.7 docker 容器进行测试,并且我已经下载了 MySQL Connector/J 8.0,建议与 MySQL Server 5.7 一起使用。根据 liquibase 自述文件,我将 mysql-connector-java-8.0.12.jar 放在 /usr/local/liquibase/lib/ 中:
liquibase 脚本会自动扫描“lib”目录,并将所有 .jar 文件添加到类路径中。 如果您有想要自动包含的 JDBC 驱动程序或 Liquibase 扩展,请将它们添加到此目录。
在我的项目测试目录中,我有以下liquibase.properties 文件:
classpath=/usr/local/liquibase/lib/mysql-connector-java-8.0.12.jar
driver=com.mysql.cj.jdbc.Driver
changeLogFile=db.changelog-1.0.xml
url="jdbc:mysql://localhost:4409/myDatabase"
username=myUser
password=myPassword
我想在端口 4409 上从我的开发数据库的当前状态生成一个更改日志,然后(在集成例程和触发器之后)在端口 4408 上的一个空数据库上运行该更改日志,然后进行比较以查看两者是否相同,然后从那里与生产数据库执行差异,以测试更改的集成程度。所以我的第一步是从我的liquibase.porperties 文件所在的同一目录中运行以下命令:
liquibase generateChangeLog
结果如下输出:
Starting Liquibase at Thu, 23 Aug 2018 07:37:21 PDT (version 3.6.2 built at 2018-07-03 11:28:09)
Unexpected error running Liquibase: liquibase.exception.DatabaseException: Connection could not be created to "jdbc:mysql://localhost:4409/myDatabase" with driver com.mysql.cj.jdbc.Driver. Possibly the wrong driver for the given database URL
liquibase.exception.DatabaseException: liquibase.exception.DatabaseException: liquibase.exception.DatabaseException: Connection could not be created to "jdbc:mysql://localhost:4409/myDatabase" with driver com.mysql.cj.jdbc.Driver. Possibly the wrong driver for the given database URL
at liquibase.integration.commandline.CommandLineUtils.createDatabaseObject(CommandLineUtils.java:132)
at liquibase.integration.commandline.Main.doMigration(Main.java:953)
at liquibase.integration.commandline.Main.run(Main.java:191)
at liquibase.integration.commandline.Main.main(Main.java:129)
Caused by: liquibase.exception.DatabaseException: liquibase.exception.DatabaseException: Connection could not be created to "jdbc:mysql://localhost:4409/myDatabase" with driver com.mysql.cj.jdbc.Driver. Possibly the wrong driver for the given database URL
at liquibase.database.DatabaseFactory.openConnection(DatabaseFactory.java:254)
at liquibase.database.DatabaseFactory.openDatabase(DatabaseFactory.java:149)
at liquibase.integration.commandline.CommandLineUtils.createDatabaseObject(CommandLineUtils.java:97)
... 3 common frames omitted
Caused by: liquibase.exception.DatabaseException: Connection could not be created to "jdbc:mysql://localhost:4409/myDatabase" with driver com.mysql.cj.jdbc.Driver. Possibly the wrong driver for the given database URL
at liquibase.database.DatabaseFactory.openConnection(DatabaseFactory.java:249)
... 5 common frames omitted
注意:由于我已将连接器文件包含在 liquibase lib 目录中,因此根据上面自述文件中的引用,我不必指定类路径。我已经尝试了两种方式并收到相同的错误。此外,我尝试使用我的 maven 本地 repo 中的 mysql-connector-java-5.1.32.jar,并将 liquibase 属性文件中的驱动程序调整为 driver=com.mysql.jdbc.Driver,但仍然出现相同的错误。
现在,这是令人困惑的地方:如果我执行以下命令而不是使用 liquibase 属性文件:
liquibase \
--classpath=/usr/local/liquibase/lib/mysql-connector-java-8.0.12.jar \
--driver=com.mysql.cj.jdbc.Driver \
--changeLogFile=db.changelog-1.0.xml \
--url="jdbc:mysql://localhost:4409/myDatabase" \
--username=myUser \
--password=myPassword \
generateChangeLog
它成功生成了更新日志文件,输出如下:
Starting Liquibase at Thu, 23 Aug 2018 09:54:41 PDT (version 3.6.2 built at 2018-07-03 11:28:09)
Thu Aug 23 09:54:43 PDT 2018 WARN: Establishing SSL connection without
server's identity verification is not recommended. According to MySQL
5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be
established by default if explicit option isn't set. For compliance
with existing applications not using SSL the verifyServerCertificate
property is set to 'false'. You need either to explicitly disable SSL
by setting useSSL=false, or set useSSL=true and provide truststore for
server certificate verification.
Liquibase command 'generateChangeLog' was executed successfully.
现在,我还有其他想要解决的问题,例如为什么生成的变更日志包含备注,但是当将变更日志应用到空数据库时,每个表的第一列上的备注不包括在内,或者当我执行diffChangeLog 两者之间,并尝试使用我得到的结果更改日志更新数据库,并且错误表明更改具有验证失败:mysql 不支持 setColumnRemarks,或者 diff 生成的视图启用了 replaceIfExists 但更新引发错误表已经存在。无论如何,在我为这些问题发布单独的线程之前,我想为什么不从我无法解决的第一个问题开始工作,看看是否在某个地方这可能会导致其他问题。
【问题讨论】:
-
奇怪的是,您的堆栈跟踪指向 this 源文件中的第 254 行,但什么都没有。你确定你使用的是 liquibase 3.6.2 吗?
-
@bilak 你需要选择3.6.2。分支供源代码参考。
-
@bilak 是的,版本是 3.6.2。检查第 254 行here。您正在寻找错误的分支。如果您检查分支 3.6.x 或标记 liquibase-parent-3.6.2,您可以看到堆栈跟踪匹配。
-
@Husain 尝试启动 liquibase,并将日志级别设置为调试。有一些日志消息 liquibase 仅在调试级别时生成,这可能有助于查看 liquibase 是否从属性文件中获取驱动程序属性。
-
--logLevel=debug在命令行:)