liquibase mysql jdbc驱动程序连接错误,使用liquibase.properties

42fyovps  于 2021-06-20  发布在  Mysql
关注(0)|答案(1)|浏览(402)

我目前正在评估liquibase作为数据库版本控制解决方案。我在ubuntu 16.04 lts上运行,java版本为“1.8.0µ”。我安装了liquibase 3.6.2,在4408和4409端口上安装了两个MySQL5.7 docker容器进行测试,下载了MySQLConnector/J8.0,建议与MySQLServer5.7一起使用。我把 mysql-connector-java-8.0.12.jar 在/usr/local/liquibase/lib/中,根据liquibase自述:
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上开发数据库的当前状态生成一个changelog,然后(在集成例程和触发器之后)在端口4408上的空数据库上运行这个changelog,然后执行diff以查看两者是否相同,然后从那里对生产数据库执行diff以测试更改的集成程度。因此,我的第一步是从 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

它成功生成具有以下输出的changelog文件:

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.

现在,我还想解决其他问题,比如为什么生成的changelog包含注解,但是当将changelog应用到空数据库时,每个表的第一列上的注解都不包含,或者当我在这两个表之间执行diffchangelog并尝试用得到的changelog更新数据库时,出现了错误更改的验证失败:mysql不支持setcolumnremarks,或者diff生成的视图启用了replaceifexists,但是更新抛出一个错误,说明表已经存在。无论如何,在我为这些问题发布一个单独的线程之前,我想为什么不从我无法解决的第一个问题开始工作,看看这是否会导致其他问题。

ltqd579y

ltqd579y1#

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

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

相关问题