Using Liquibase with MariaDB, skySQL, or MariaDB AWS RDS
To test your connection, try running Liquibase with the JDBC driver located in the same directory as Liquibase:
The purpose of this document is to guide you through the process of creating a new Liquibase project with MariaDB skySQL or MariaDB AWS RDS on a Windows machine. In this tutorial, you will generate an example project and follow the instructions to apply and learn concepts associated with creating new Liquibase projects with MariaDB.
- If you have not installed the latest version of Liquibase, navigate to https://www.liquibase.org/download to install the software application.
- Ensure the liquibase.bat file's path is set to a location in the PATH System variable.
- Navigate to https://mariadb.com/kb/en/library/about-mariadb-connector-j/ and download the jdbc driver file for MariaDB.
Note: Place the jdbc jar driver file in a known directory so you can locate it easily.
To create a Liquibase project with MariaDB on your Windows machine, begin with the following steps:
- Create a new project folder and name it LiquibaseMariaDB.
- Place the jdbc jar driver file in the LiquibaseMariaDB folder.
- In your LiquibaseMariaDB folder, Right-click then select New>Text Document to create an empty text file.
- Rename the text file to dbchangelog.xml. changelog files contain a sequence of changesets, each of which make small changes to the structure of your database. Instead of creating an empty changelog file in step 2, you can also use an existing database to generate a changelog. In this tutorial, you will manually add a single change. To add this change:
- Open the dbchangelog.xml file and update the changelog file with the following code snippet:
- In your LiquibaseMariaDB folder Right-click and select New>Text Document to create a new text file.
- Rename the text file to liquibase.properties.
- Edit the liquibase.properties file to add the following properties:
MariaDB AWS RDS sample liquibase.properties file
When using AWS RDS database instance, the host name should be copied from AWS website under your RDS –> Databases –>
<database name> –> Connectivity & security –> Endpoint
<copy the endpoint value>. This value should look similar to the value mentioned in the liquibase.properties example above.
MariaDB skySQL sample liquibase.properties file
When using skySQL database instance, the host name should be copied from the cloud.mariadb.com/skysql website under your skySQL account –> Your Services –>
<service name> –> Click the “Show Credentials” button.
Now you copy the connection information to your liquibase.properties. Those values should look similar to the values mentioned in the liquibase.properties example above.
Also, under “Certificate authority chain” click on the Download link to download your skysql_chain.pem certificate and place it in your project folder.
In general, the url property should follow this template:
Note: If you already have a Liquibase Pro key and want to apply it to your project, add the following property to your liquibase.properties file.
- Adding a changeset to the changelog – changesetsare uniquely identified by “author” and ”id” attributes. Liquibase attempts to execute each changeset in a transaction that is committed at the end. In the dbchangelog.xml file line 9 to 20 add a new “department” create table change set as follows:
Note: This create table change set is XML format. The corresponding SQL statement should look like the following:
- Open the command prompt. Navigate to the LiquibaseMariaDB_RDS directory.
Run the following command:
- From a database UI Tool, check your database changes under “mydatabase”. You should see a new “department” table added to the database. For example:
Also, you should see two more tables:
- DATABASECHANGELOG tracking table – This table keeps a record of all the changesets that were deployed. This way, next time when you deploy again, the changesets in the changelog will be compared with the DATABASECHANGELOG tracking table and only the new changesets that were not found in the DATABASECHANGELOG will be deployed. You will notice that a new row was created in that table with the changeset information we have just deployed. For this example:
- DATABASECHANGELOGLOCK – This table is used internally by Liquibase to manage access to the changelog table during deployment.