Using Liquibase with MariaDB, skySQL, or MariaDB AWS RDS

MariaDB delivers operational agility with key enterprise features, including real ACID compliance and full SQL. It provides two solutions:

  • MariaDB Platform, which includes an open-source database solution—MariaDB Server along with Xpand, ColumnStore, and MaxScale.
  • MariaDB Cloud (or MariaDB SkySQL), which is a cloud database service (DBaaS) that delivers MariaDB Platform on the expert-maintained cloud infrastructure from MariaDB Corporation.

You can also use MariaDB on Amazon RDS.

Note: For more information, see the MariaDB Knowledge Base.

Supported Versions

  • 10.3
  • 10.4
  • 10.5

Note: The supported versions are the versions that were tested with Liquibase Test Harness.

Prerequisites

Before using Liquibase and MariaDB, ensure you have completed the following:

Driver Information

To use Liquibase and MariaDB, you need to have the JDBC jar file:

  1. Ensure you have downloaded the MariaDB Connector/J jar driver file to connect to MariaDB. To download the driver file, select Download MariaDB Connector/J. Once you open the download page, you need to select Java 8 Connector in the Product dropdown.
  2. Place your mariadb-java-client-version.jar file in the liquibase/lib directory.

Note: If you put the mariadb-java-client-version.jar file in any other directory, specify the path to it in the liquibase.properties file: classpath:../path_to_drivers/mariadb-java-client-version.jar. For more information, see Creating and configuring a liquibase.properties file.

If you use Maven, you also need to download the MariaDB driver jar file and put the driver in a location that your Maven build can access. Configure the Maven pom.xml file to use the local copy of the driver jar file. For example:

<dependency>
<groupId>org.mariadb.jdbc</groupId>
<artifactId>mariadb-java-client</artifactId>
<version>2.7.3</version>
</dependency>

Testing Your Connection

For Liquibase and MariaDB to work, you need to:

  1. Ensure your MariaDB is configured. See the following:
  1. Specify the database URL in the liquibase.properties file or as a parameter to the command in the CLI. See the following:
  1. Create a text file called changelog (.xml, .sql, .json, or .yaml) in your project directory and add a changeset.
  1. Run the status command to see whether the connection is successful. Specify the name of the changelog you created in place of changelog.xml. Also, to run Liquibase commands, you need to specify your username and password in the liquibase.properties file or on the command line. However, the username and password attributes are not required for connections and systems which use alternate means of authentication.
  2. liquibase --username=test --password=test --changeLogFile=changelog.xml status

    Note: Alternatively, you can add the changeLogFile attribute to your liquibase.properties file.

  1. Run your first update with the Liquibase update command, which will make changes to your database. You can also run the updateSQL command if you want to inspect the SQL before running the update command.
  2. liquibase --changeLogFile=changelog.xml updateSQL
    liquibase --changeLogFile=changelog.xml update

After your first update, you will see a new table along with the DATABASECHANGELOG and DATABASECHANGELOGLOCK tables added to the database:

  • DATABASECHANGELOG table. This table keeps a record of all the changesets that were deployed. When you deploy, the changesets in the changelog are compared with the DATABASECHANGELOG tracking table, and only the new changesets that were not found in the DATABASECHANGELOG will be deployed.
  • DATABASECHANGELOGLOCK table. This table is used internally by Liquibase to manage access to the DATABASECHANGELOG table during deployment and ensure only one instance of Liquibase is updating the database at a time, whether that is creating, updating or deleting changes.

MariaDB Server

  • Check the status of the database by running the SHOW [GLOBAL | SESSION] STATUS command.
  • Specify the database URL in the liquibase.properties file as follows:
  • url: jdbc:mariadb://<host>:<port>/<dbname>

MariaDB on AWS RDS

  • Check the connection by using the mysql utility and running the following:
  • mysql -h <endpoint> -P 3306 -u <mymasteruser> -p

    Note: The alternative way is to connect with the SSL certificate.

    You can find the connection information in the AWS Management Console:

    1. Open the Amazon RDS console
    2. Select Databases and choose the needed database
    3. Select Connectivity & security. You will see all information under Endpoint & Port.

    To find the connection information using the AWS CLI and RDS API, refer to the Connecting to a DB instance running the MariaDB database engine documentation.

  • Specify the database URL in the liquibase.properties file as follows:
  • url: jdbc:mariadb://<endpoint>:<port>/<dbname>

    Example: url:jdbc:mariadb://myrds.cz1j1vh9uvuo.us-east-1.rds.amazonaws.com:3306/mydatabase

Supported Commands and Change Types

Change Type Supported Command Supported
addAutoIncrement Supported calculateCheckSum <id> Supported
addCheckConstraint Supported changelogSync Supported
addColumn Supported changelogSyncSQL Supported
addDefaultValue Supported changelogSyncToTag Supported
addForeignKeyConstraint Supported changelogSyncToTagSQL Supported
addLookupTable Supported clearCheckSums Supported
addNotNullConstraint Supported dbDoc Supported
addPrimaryKey Supported deactivateChangeLog Supported
addUniqueConstraint Supported diff Supported
alterSequence Supported diff JSON Supported
createFunction Supported diffChangeLog Supported
createIndex Supported dropAll Supported
createPackage Supported futureRollbackCountSQL <value> Supported
createPackageBody Supported future-rollback-from-tag-sql <tag> Supported
createProcedure Supported futureRollbackSQL Supported
createSequence Supported generateChangeLog Supported
createSynonym Not Supported help Supported
createTable Supported history Supported
createTrigger Supported listLocks Supported
createView Supported markNextChangeSetRan Supported
customChange Supported markNextChangeSetRanSQL Supported
delete Supported registerChangeLog Supported
disableCheckConstraint Not Supported releaseLocks Supported
disableTrigger Not Supported rollback <tag> Supported
dropAllForeignKeyConstraints Supported rollbackCount <value> Supported
dropCheckConstraint Supported rollbackCountSQL <value> Supported
dropColumn Supported rollbackOneChangeSet Supported
dropDefaultValue Supported rollbackOneChangeSetSQL Supported
dropForeignKeyConstraint Supported rollbackOneUpdate Supported
dropFunction Supported rollbackOneUpdateSQL Supported
dropIndex Supported rollbackSQL <tag> Supported
dropNotNullConstraint Supported rollbackToDate Supported
dropPackage Supported rollbackToDateSQL Supported
dropPackageBody Supported snapshot Supported
dropPrimaryKey Supported snapshotReference Supported
dropProcedure Supported status --verbose Supported
dropSequence Supported syncHub Supported
dropSynonym Not Supported tag <tag string> Supported
dropTable Supported tagExists <tag string> Supported
dropTrigger Supported unexpectedChangeSets Supported
dropUniqueConstraint Supported update Supported
dropView Supported updateSQL Supported
empty Supported updateCount <value> Supported
enableCheckConstraint Not Supported updateCountSQL <value> Supported
enableTrigger Not Supported updateTestingRollback Supported
executeCommand Supported updateToTag <tag> Supported
insert Supported updateToTagSQL <tag> Supported
loadData Supported validate Supported
loadUpdateData Supported    
markUnused Not Supported    
mergeColumns Supported    
modifyDataType Supported    
output Supported    
renameColumn Supported    
renameSequence Not Supported    
renameTable Supported    
renameTrigger Not Supported    
renameView Supported    
setColumnRemarks Supported    
setTableRemarks Supported    
sql Supported    
sqlFile Supported    
stop Supported    
tagDatabase Supported    
update Supported    

Related Links