我目前正在评估Liquibase作为数据库版本控制解决方案。我在具有Java版本“ 1.8.0_181”的Ubuntu 16.04 LTS上运行。我已经安装了Liquibase 3.6.2,已经在端口4408和4409上安装了两个MySQL 5.7 docker容器以进行测试,并且我已经下载了建议与MySQL Server 5.7一起使用的MySQL Connector/J 8.0。按照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目录中,因此根据上述自述文件的引文,我不必指定类路径。我已经尝试了两种方式,并收到了相同的错误。此外,我尝试使用mysql-connector-java-5.1.32.jar
(这是我的Maven本地存储库中的内容),并将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,但更新引发了以下错误表已经存在。无论如何,在我为这些问题发布单独的线程之前,我想为什么从第一个问题起就无法解决我无法解决的问题,以了解这是否可能导致其他问题。
答案 0 :(得分:1)
所以解决方案非常简单,我不敢相信我没有看到它。在liquibase.properties
文件中,URL不应该带引号。将文件编辑为此:
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
成功生成变更日志文件。必须使用在属性文件和命令行中解析参数的方式。