Need Liquibase® support? Liquibase Pro is now available! Try it out free.
2018 XML Announcement

Liquibase Tutorial: Getting Started Using SQL Scripts


This tutorial builds on the setup that is described in the Quick Start.

Step 1: Create a sql Folder

In the liquibase project folder that you created, create a sql folder. This is the folder in which you will place SQL scripts that Liquibase will track, version, and deploy.

Step 2: Setup the Change Log

This is a one-time step to configure a change log to point to the sql folder that will contain SQL scripts. Create and save a file in the liquibase project directory you created. The file should be named myChangeLog.xml. The contents of myChangeLog.xml should be as follows:

<?xml version="1.0" encoding="UTF-8"?>

  <includeAll path="sql"/>

Step 2: Add a SQL Script to the sql Folder

With a file from the tutorial setup and the newly created myChangeLog.xml, we are now ready to start adding SQL scripts to the sql folder. Liquibase will order the scripts in the folder alphanumerically. Create a file named 001_create_person_table.sql with the following and save it in the sql folder:

create table PERSON (
    ID int not null,
    FNAME varchar(100) not null

Step 3: Deploy Your First Change!

We are now ready to deploy our first script! Open a terminal and run LB_HOME/liquibase update if on a UNIX system or LB_HOME\liquibase.bat update if on Windows.

Step 4: Check Your Database

You will see that your database now contains a table called “PERSON”. To inpsect the H2 database that is a part of the tutorial, open a terminal, navigate to the LB_HOME folder where you extracted the Liquibase *.zip or the *.tar.gz to and then to the lib subdirectory where the h2 driver jar is located. Run java -jar h2-1.4.199.jar.Note: enter the specific version of the h2*.jar that you downloaded! Enter the JDBC URL, User Name, and Password from the file you created per the tutorial setup. You will notice two other tables are created as well: “databasechangelog” and “databasechangeloglock”. The databasechangelog table contains a list of all the changes that have been run against the database. The databasechangeloglock table is used to make sure two machines don’t attempt to modify the database at the same time.

Next Steps

  • This quick-start guide is designed to quickly introduce you to Liquibase. For a full description of all its capabilities, see the Liquibase Manual, read the best practices and visit the forums.
  • If you have an existing project you are looking to add Liquibase to, visit the Existing Project page.
  • If you are interested in commercial support, training, or consulting, consider Liquibase Pro.

Missing, incomplete or wrong information? Please send a pull request