Command Line Interface

Liquibase can be run from the command line by running:

                liquibase [global options] [command] [command parameters]
            

The command line migrator works well when you want to do migrations on demand, but don't have Ant or Maven available such as on servers. The command line migrator also gives you more control over the process than the Servlet Listener, Ant or Maven do, allowing you to run maintenance commands like outputting SQL and listing/releasing database changelog locks.

Any values found after the command on the command line invocation will be considered a command parameter. The command line processor will validate whether the command line parameters are allowed for the current command. If the current command does not allow command line parameters or the parameter appears to be an incorrect format, then an error message of ‘unexpected command parameter' will be logged and the execution will terminate.

The command line migrator also allows you to:

If you run the command line migrator without any arguments, you will get a help message listing all of your commands. See the following topics for a full list of commands:

Using a liquibase.properties file

If you do not want to always specify options on the command line, you can create a properties file that contains default values. By default, Liquibase will look for a file called liquibase.properties in the current working directory, but you can specify an alternate location with the --defaultsFile flag. If you have specified an option in a properties file and specify the same option on the command line, the value on the command line will override the properties file value.

Examples

Standard Update Run

                java -jar liquibase.jar \
      --driver=oracle.jdbc.OracleDriver \
      --classpath=\path\to\classes:jdbcdriver.jar \
      --changeLogFile=com/example/db.changelog.xml \
      --url="jdbc:oracle:thin:@localhost:1521:oracle" \
      --username=scott \
      --password=tiger \
      update
            

Run update pulling changelogs from a .WAR file

                java -jar liquibase.jar \
      --driver=oracle.jdbc.OracleDriver \
      --classpath=website.war \
      --changeLogFile=com/example/db.changelog.xml \
      --url=jdbc:oracle:thin:@localhost:1521:oracle \
      --username=scott \
      --password=tiger \
      update
            

Run update pulling changelogs from an .EAR file

                java -jar liquibase.jar \
      --driver=oracle.jdbc.OracleDriver \
      --classpath=application.ear \
      --changeLogFile=com/example/db.changelog.xml \
      --url=jdbc:oracle:thin:@localhost:1521:oracle \
      --username=scott \
      --password=tiger \
      update
            

Don't execute changeSets, save SQL to /tmp/script.sql

                java -jar liquibase.jar \
        --driver=oracle.jdbc.OracleDriver \
        --classpath=jdbcdriver.jar \
        --url=jdbc:oracle:thin:@localhost:1521:oracle \
        --username=scott \
        --password=tiger \
        updateSQL > /tmp/script.sql
            

List locks on the DATABASECHANGELOGLOCK table

                java -jar liquibase.jar \
        --driver=oracle.jdbc.OracleDriver \
        --classpath=jdbcdriver.jar \
        --url=jdbc:oracle:thin:@localhost:1521:oracle \
        --username=scott \
        --password=tiger \
        listLocks
            

Runs Liquibase using defaults from ./liquibase.properties

                java -jar liquibase.jar update
            

liquibase.properties

                
                    driver
                    :  oracle.jdbc.OracleDriver  
classpath:  jdbcdriver.jar  
url:  jdbc:oracle:thin:@localhost:1521:oracle  
username:  scott  
password:  tiger
            

Export Data from Database

This will export the data from the targeted database and put it in a folder “data” in a file name specified with <insert file name>.

                java -jar liquibase.jar --changeLogFile="./data/<insert file name> " --diffTypes="data" generateChangeLog
            

Update passing changelog parameters

                liquibase.bat update -Dengine=myisam
            

Unicode

MySQL

Add URL parameters useUnicode=true and characterEncoding=UTF-8 to set character encoding to utf8.

Since v5.1.3 Connector/J now auto-detects servers configured with character_set_server=utf8mb4 or treats the Java encoding utf-8 passed using characterEncoding=… as utf8mb4.

                --url="jdbc:mysql://localhost/dbname?useUnicode=true&characterEncoding=UTF-8
            

See the MySQL Connector J Using Character Sets and Unicode topic for more information.