Liquibase MySQL Database Support
- 8.0 – LIQUIBASE CERTIFIED (v4.2+)
- 5.7 – LIQUIBASE CERTIFIED (v4.2+)
- 5.6 – COMMUNITY TESTED
- 5.5 – COMMUNITY TESTED
Supported Commands & Features
Operation | Community | Pro | Business | Enterprise |
---|---|---|---|---|
Update | – | – | ||
— Deploy Native MySQL Scripts | – | – | – | – |
Rollback | – | – | ||
— Targeted Rollback | – | – | – | |
Snapshot/ GenerateChangelog | – | – | ||
Diff/DiffChangelog | – | – | ||
— Diff: JSON Output | – | – | – | |
Status/History | – | – | ||
Rules | – | – | – | – |
Packager | – | – | – | – |
Forecast | – | – | – | – |
Download Community | Try Pro Free |
Supported Objects
Object Support | Community | Pro | Business | Enterprise |
---|---|---|---|---|
Tables | – | – | ||
Views | – | – | ||
Indexes | – | – | ||
Constraints | – | – | ||
Synonyms | N/A | N/A | N/A | |
Sequences | – | – | ||
Stored Logic • Procedures • Functions • Triggers | Procedure support only | – | – | |
Download Community | Try Pro Free |
Get Started: Using MySQL with Liquibase
It’s easy to get started using Liquibase Community and Liquibase Pro for updating your MySQL databases. Contact us on how to get started with Liquibase Business or Enterprise.
1. Download Software
a. Download and install Liquibase Community. If you’d like to use Liquibase Pro, get a trial key or purchase Liquibase Pro.
b. Download the latest MySQL JDBC Driver for your system.
2. Configure Liquibase
a. Configure the liquibase.properties file.
# Database Short Name: mysql
# Path to the Liquibase changelog file that contains
# your database changes (example in step #3 below)
changeLogFile=../path/to/file/changelog.xml
# JDBC Driver Configuration
driver=com.mysql.cj.jdbc.Driver
classpath=../Liquibase_Drivers/mysql-connector-java-8.0.20.jar
# Database Connection Configuration (access the database)
url=jdbc:mysql://localhost:3306/my_database
username=<db username>
password=<db password>
b. (optional) Configure Maven integration.
1. Configure the MySQL driver in the Maven POM file dependency section.
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.liquibase</groupId>
<artifactId>liquibase-example</artifactId>
<version>0.0.1-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.21</version>
</dependency>
</dependencies>
</project>
2. Configure the Maven update goal for the Liquibase Maven plugin and reference the liquibase.properties file defined above in the Maven configuration.
<project>
<build>
<plugins>
<plugin>
<groupId>org.liquibase</groupId>
<artifactId>liquibase-maven-plugin</artifactId>
<version>4.2.0</version>
<configuration>
<propertyFile>./liquibase.properties</propertyFile>
</configuration>
<executions>
<execution>
<phase>process-resources</phase>
<goals>
<goal>update</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
3. Create the First Database Change
Create a changelog with the first database change.
changelog.xml file
<?xml version="1.1" encoding="UTF-8" standalone="no"?> <databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog" xmlns:ext="http://www.liquibase.org/xml/ns/dbchangelog-ext" xmlns:pro="http://www.liquibase.org/xml/ns/pro" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog-ext http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-ext.xsd http://www.liquibase.org/xml/ns/pro http://www.liquibase.org/xml/ns/pro/liquibase-pro-4.2.xsd http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-4.2.xsd"> <changeSet id="1" author="bob"> <createTable tableName="department"> <column name="id" type="int"> <constraints primaryKey="true" nullable="false"/> </column> <column name="name" type="varchar(50)"> <constraints nullable="true"/> </column> </createTable> </changeSet> </databaseChangeLog>
changelog.sql file
--liquibase formatted sql --changeset bob:1 create table department2 ( id int primary key not null, name varchar(50) );
4. Run Example Command (update)
Run the Liquibase status and update commands to see the change applied to the database.
% liquibase status
Liquibase Community 3.10.0 by Datical
1 change sets have not been applied to testuser@172.17.0.1@jdbc:mysql://localhost:3306/testdb1
Liquibase command 'status' was executed successfully.
% liquibase update
Liquibase Community 3.10.0 by Datical
Liquibase: Update has been successful.
% liquibase status
Liquibase Community 3.10.0 by Datical
testuser@172.17.0.1@jdbc:mysql://localhost:3306/testdb1 is up to date
Liquibase command 'status' was executed successfully.
$ mvn liquibase:update
[INFO] Scanning for projects…
[INFO]
[INFO] -------< com.liquibase:liquibase-includeAll-changeLogDirectory >--------
[INFO] Building liquibase-includeAll-changeLogDirectory 0.0.1-SNAPSHOT
[INFO] -------------------[ jar ]--------------------
[INFO]
[INFO] --- liquibase-maven-plugin:4.2.0:update (default-cli) @ liquibase-includeAll-changeLogDirectory ---
[INFO] ----------------------------------------------
[INFO] Parsing Liquibase Properties File
[INFO] File: ./liquibase.properties
[INFO] 'classpath' in properties file is not being used by this task.
[INFO] ----------------------------------------------
[INFO]
[INFO]
[INFO] Liquibase Community 4.2.0 by Datical
[INFO] Starting Liquibase at 20:42:43 (version 4.2.0 #18 built at 2020-11-13 16:49+0000)
[INFO] Parsing Liquibase Properties File ./liquibase.properties for changeLog parameters
[INFO] Executing on Database: jdbc:mysql://localhost:3306/testdb1
Dec 2, 2020 8:42:44 PM liquibase.lockservice
INFO: Successfully acquired change log lock
Dec 2, 2020 8:42:44 PM liquibase.changelog
INFO: Reading from DATABASECHANGELOG
Dec 2, 2020 8:42:44 PM liquibase.changelog
INFO: Custom SQL executed
Dec 2, 2020 8:42:44 PM liquibase.changelog
INFO: ChangeSet ./changelog.sql::2::bob ran successfully in 24ms
Dec 2, 2020 8:42:44 PM liquibase.lockservice
INFO: Successfully released change log lock
[INFO] ---------------------------------------------
[INFO]
[INFO] ---------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ---------------------------------------------
[INFO] Total time: 1.578 s
[INFO] Finished at: 2020-12-02T20:42:44-05:00
[INFO] ---------------------------------------------
Liquibase Documentation
Articles by Community Contributors
-
How to integrate Liquibase with Spring Boot and MySQL
—Tiago Melo, Senior Software Developer
-
How to use Liquibase with Maven and MySQL
— Yegor Bugayenko, Director of System Programming-
Video: How to integrate Liquibase with Maven
— MT Software
-
Video: How to integrate Liquibase with Maven
-
How to use Liquibase with the Command Line (CLI) and MySQL
— Indira Nellutla, QA Manager -
How to create a Micronaut app with Liquibase, Groovy, and MySQL
— Oscar Hernandez, Software Developer
Get Help
- Discuss Liquibase with community users and experts on the Liquibase Forum.
- Ask a question on Stack Overflow or the Liquibase Discord channel.
- Learn more about Liquibase paid support.