This post has already been read 9453 times!

1. Install Java

Liquibase 3.x requires Java 1.6+ so lets get that installed first

$ sudo yum install java-1.7.0-openjdk

2. Get the Liquibase Code

I'm just going to install put Liquibase in the home directory for now


$ wget http://sourceforge.net/projects/liquibase/files/Liquibase%20Core/liquibase-3.1.1-bin.tar.gz/download
$ tar zxvf liquibase-3.1.1-bin.tar.gz
$ sudo chmod + x ./liquibase
$ ./liquibase --version

3. Install MySQL

$ sudo yum install mysql mysql-server
$ sudo chkconfig --levels 235 mysqld on
$ sudo service mysqld start
$ /usr/bin/mysqladmin -u root password 'root'
$ mysql -u root -p root

4. Install the MySQL connector for Java

$ wget http://dev.mysql.com/get/Downloads/Connector-J/mysql-connector-java-5.1.30.tar.gz
$ tar zxvf mysql-connector-java-5.1.30.tar.gz

5. Create the MySQL database

$ mysql -uroot -proot
mysql> create database example;
mysql> exit;

6. Create a Changelog file

$ vim ./changelog.xml

Add the following...

 <?xml version="1.0" encoding="UTF-8"?>  
 <databaseChangeLog  
   xmlns="http://www.liquibase.org/xml/ns/dbchangelog"  
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
   xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.1.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="false"/>  
       </column>  
       <column name="active" type="boolean" defaultValueBoolean="true"/>  
     </createTable>  
   </changeSet>  
 </databaseChangeLog> 

7. Run Liquibase

$ ./liquibase --driver=com.mysql.jdbc.Driver --classpath=mysql-connector-java-5.1.30/mysql-connector-java-5.1.30-bin.jar  --changeLogFile=changelog.xml --url="jdbc:mysql://localhost/example" --username=root --password=root update

8. Create a liquibase.properties file


$ vim ~/liquibase.properties

Add the following...

 driver: com.mysql.jdbc.Driver  
 classpath: mysql-connector-java-5.1.30/mysql-connector-java-5.1.30-bin.jar  
 url: jdbc:mysql://localhost/example  
 username: root  
 password: root  

9. Run Liquibase with the properties file

$ ./liquibase --changeLogFile=changelog.xml update

Leave a Reply

Post Navigation