MySQL

Getting Started with Liquibase: Easy Database Versioning

Liquibase is an open-source tool that simplifies database versioning by allowing developers to track, apply, and roll back schema changes easily using structured changelog files instead of manual SQL scripts.

March 19, 2025

Keeping track of database changes can get messy, especially when multiple developers are working on the same project.

That’s where Liquibase comes in.

Liquibase is a tool that helps you manage database changes in a structured way—just like version control for your code (eg. Git).

Let’s break it down in simple terms.

What is Liquibase?

Liquibase is an open-source database versioning tool that helps developers track, apply, and roll back database changes.

Instead of manually writing SQL scripts every time your schema changes, you define changes in a structured file, and Liquibase applies them automatically.

Why use it?

  • Keeps track of all database changes
  • Allows easy rollbacks if something goes wrong
  • Works with many databases (MySQL, PostgreSQL, Oracle, etc.)
  • Automates database updates across teams

How Liquibase Works

Liquibase uses a changelog file to store database changes.

This file can be written in XML, YAML, JSON, or SQL.

It contains change sets, which describe changes like adding tables, columns, or indexes.

Here’s an example of a simple changelog.yaml file:

databaseChangeLog:
  - changeSet:
      id: 1
      author: dev
      changes:
        - createTable:
            tableName: users
            columns:
              - column:
                  name: id
                  type: int
                  autoIncrement: true
              - column:
                  name: name
                  type: varchar(255)

This tells Liquibase:

  • "Create a table called users"
  • "Add two columns: id (an auto-incrementing integer) and name (a text field)"
  • "Track this as change #1 made by 'dev'"

How to Use Liquibase

1. Install Liquibase

Download and install Liquibase from the official site: liquibase.org

2. Configure the Database Connection

Create a liquibase.properties file to define your database settings:

url=jdbc:mysql://localhost:3306/mydatabase
username=root
password=yourpassword
driver=com.mysql.cj.jdbc.Driver
changelog-file=changelog.xml

3. Apply Changes to the Database

Once Liquibase is set up, apply your changes by running:

liquibase update

This scans the changelog.xml file and applies any new changes to the database.

4. Rolling Back Changes

Made a mistake? No problem!

You can undo the last change:

liquibase rollbackCount 1

This reverts the last change set, keeping your database clean and version-controlled.

Key Takeaway

Liquibase makes managing database changes easy, reducing errors and keeping everything organized.

Whether you're working solo or in a team, it ensures everyone’s database stays in sync.

If you're tired of writing endless SQL scripts, give Liquibase a try!