Liquibase unknown database error.

Hi ,

I am using liquibase 3.4.1 but I got one issue regarding database , my database name is combination of small & capital letters.

While running liquibase update it is showing unknown database error . It converts all letters into small case. We are using

mysql database server.

Following is the error log

DEBUG 26/11/15 3:08 PM: liquibase: Release Database Lock

DEBUG 26/11/15 3:08 PM: liquibase: Executing UPDATE database command: UPDATE myTestDB.DATABASECHANGELOGLOCK SET LOCKED = 0, LOCKEDBY = NULL, LOCKGRANTED = NULL WHERE ID = 1

INFO 26/11/15 3:08 PM: liquibase: Successfully released change log lock

Unexpected error running Liquibase: java.sql.SQLException: Unknown database ‘mytestdb’

SEVERE 26/11/15 3:08 PM: liquibase: java.sql.SQLException: Unknown database ‘mytestdb’

liquibase.exception.UnexpectedLiquibaseException: liquibase.exception.DatabaseException: java.sql.SQLException: Unknown database ‘mytestdb’

at liquibase.changelog.StandardChangeLogHistoryService.init(StandardChangeLogHistoryService.java:102)

at liquibase.Liquibase.checkLiquibaseTables(Liquibase.java:1074)

at liquibase.Liquibase.update(Liquibase.java:203)

at liquibase.Liquibase.update(Liquibase.java:190)

at liquibase.integration.commandline.Main.doMigration(Main.java:1096)

at liquibase.integration.commandline.Main.run(Main.java:180)

at liquibase.integration.commandline.Main.main(Main.java:99)

Caused by: liquibase.exception.DatabaseException: java.sql.SQLException: Unknown database ‘mytestdb’

at liquibase.snapshot.ResultSetCache.get(ResultSetCache.java:78)

at liquibase.snapshot.JdbcDatabaseSnapshot$CachingDatabaseMetaData.getTables(JdbcDatabaseSnapshot.java:343)

at liquibase.snapshot.jvm.TableSnapshotGenerator.snapshotObject(TableSnapshotGenerator.java:32)

at liquibase.snapshot.jvm.JdbcSnapshotGenerator.snapshot(JdbcSnapshotGenerator.java:60)

at liquibase.snapshot.SnapshotGeneratorChain.snapshot(SnapshotGeneratorChain.java:50)

at liquibase.snapshot.jvm.JdbcSnapshotGenerator.snapshot(JdbcSnapshotGenerator.java:63)

at liquibase.snapshot.SnapshotGeneratorChain.snapshot(SnapshotGeneratorChain.java:50)

at liquibase.snapshot.jvm.JdbcSnapshotGenerator.snapshot(JdbcSnapshotGenerator.java:63)

at liquibase.snapshot.SnapshotGeneratorChain.snapshot(SnapshotGeneratorChain.java:50)

at liquibase.snapshot.jvm.JdbcSnapshotGenerator.snapshot(JdbcSnapshotGenerator.java:63)

at liquibase.snapshot.SnapshotGeneratorChain.snapshot(SnapshotGeneratorChain.java:50)

at liquibase.snapshot.jvm.JdbcSnapshotGenerator.snapshot(JdbcSnapshotGenerator.java:63)

at liquibase.snapshot.SnapshotGeneratorChain.snapshot(SnapshotGeneratorChain.java:50)

at liquibase.snapshot.jvm.JdbcSnapshotGenerator.snapshot(JdbcSnapshotGenerator.java:63)

at liquibase.snapshot.SnapshotGeneratorChain.snapshot(SnapshotGeneratorChain.java:50)

at liquibase.snapshot.jvm.JdbcSnapshotGenerator.snapshot(JdbcSnapshotGenerator.java:63)

at liquibase.snapshot.SnapshotGeneratorChain.snapshot(SnapshotGeneratorChain.java:50)

at liquibase.snapshot.DatabaseSnapshot.include(DatabaseSnapshot.java:194)

at liquibase.snapshot.DatabaseSnapshot.init(DatabaseSnapshot.java:70)

at liquibase.snapshot.DatabaseSnapshot.(DatabaseSnapshot.java:44)

at liquibase.snapshot.JdbcDatabaseSnapshot.(JdbcDatabaseSnapshot.java:21)

at liquibase.snapshot.SnapshotGeneratorFactory.createSnapshot(SnapshotGeneratorFactory.java:150)

at liquibase.snapshot.SnapshotGeneratorFactory.createSnapshot(SnapshotGeneratorFactory.java:158)

at liquibase.snapshot.SnapshotGeneratorFactory.getDatabaseChangeLogTable(SnapshotGeneratorFactory.java:165)

at liquibase.changelog.StandardChangeLogHistoryService.init(StandardChangeLogHistoryService.java:100)

… 6 more

Caused by: java.sql.SQLException: Unknown database ‘mytestdb’

at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2847)

at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1531)

at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1622)

at com.mysql.jdbc.Connection.execSQL(Connection.java:2370)

at com.mysql.jdbc.Connection.execSQL(Connection.java:2297)

at com.mysql.jdbc.Statement.executeQuery(Statement.java:1183)

at com.mysql.jdbc.DatabaseMetaData.getTables(DatabaseMetaData.java:3351)

at liquibase.snapshot.JdbcDatabaseSnapshot$CachingDatabaseMetaData$4.fastFetchQuery(JdbcDatabaseSnapshot.java:365)

at liquibase.snapshot.ResultSetCache$SingleResultSetExtractor.fastFetch(ResultSetCache.java:290)

at liquibase.snapshot.ResultSetCache.get(ResultSetCache.java:58)

… 30 more

Please can someone help me ?

Several databases do things like that - automatically convert the case of all table names, etc. written to the database to either uppercase or lowercase, and then similarly convert queries to all uppercase or lowercase. But they typically also support a mode where you quote the names, which prevents the names from being converted, and can prevent queries from working as a human might expect.

The basic rule with these kinds of databases is that if you use quotes when creating the table/column/etc., then you must also use quotes and the same case when querying. For example, if you created the database named “MyTestDB” with quotes and mixed case, then querying for mytestdb (all lower case) will not work.

To provide the correct quoting behavior for Liquibase, you can use the objectQuotingStrategy=“QUOTE_ALL_OBJECTS” attribute on your changeSet attribute or on the databaseChangeLog root element to override the default logic of “only quote objects that have to be”

Steve Donie
Principal Software Engineer
Datical, Inc. http://www.datical.com/

Several databases do things like that - automatically convert the case of all table names, etc. written to the database to either uppercase or lowercase

This is required by the SQL standard: unquoted identifiers have to be stored in uppercase and they have to be case-insensitive.