繁体   English   中英

使用 liquibase.properties 的 Liquibase MySQL JDBC 驱动程序连接错误

[英]Liquibase MySQL JDBC Driver connectivity error using liquibase.properties

我目前正在评估 Liquibase 作为数据库版本控制解决方案。 我在 Ubuntu 16.04 LTS 上运行,Java 版本为“1.8.0_181”。 我已经安装了 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 目录中包含了连接器文件,根据上面自述文件中的引用,我不必指定类路径。 我已经尝试了两种方法并收到相同的错误。 此外,我尝试使用mysql-connector-java-5.1.32.jar ,这是我的 maven 本地存储库中的内容,并将 liquibase 属性文件中的driver=com.mysql.jdbc.Driver调整为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,或者差异生成的视图启用了 replaceIfExists 但更新引发了表已存在的错误. 无论如何,在我针对这些问题发布单独的线程之前,我想为什么不从我无法解决的第一个问题开始工作,看看在此过程中的某个地方是否可能会导致其他问题。

所以解决方案真的很简单,我不敢相信我没有看到它。 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

成功生成变更日志文件。 它必须是在属性文件与命令行中解析参数的方式。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM