Installing Liquibase for MacOS and add MySQL driver

Goal

How to install liquibase locally in MacOS and add a MySQL driver

Description

This recipe is very simple one but it fits the purpose of never forgetting again what I need to do in the future, when I want liquibase installed in my host machine, already configured with the necessary dependencies for a specific driver such as MySQL.

How to

Step 1: Download liquibase for your appropriate system from Liquibase’s site, here and just install the binary. Make sure to tick in the option to add liquibase to the path, so that you can simply use it later on in your terminal. After completion, you will have a liquibase folder installed in /usr/local/opt/liquibase/.

Step 2: Download the driver that you need, for example, from here. At the current version of liquibase, MySQL is not a default driver. Before copying the driver to liquibase installation folder, make sure there is no equivalent MySQL driver in both /usr/local/opt/liquibase/lib and /usr/local/opt/liquibase/internal/lib.

Step 3: Unzip the file and copy the .jar file into the usr/local/opt/liquibase/lib (as explained here). From the previous link, it would be the following:

$> unzip mysql-connector-j-8.0.31.zip
$> sudo cp mysql-connector-j-8.0.31/mysql-connector-j-8.0.31.jar /usr/local/opt/liquibase/lib/

Step 4: Check if that is working by going to a project containing a liquibase.properties (such as the one above) and the necessary changesets to apply to your locally running MySQL:

#MySQL
changeLogFile=db.changelog-master.xml
username=root
password=
url=jdbc:mysql://127.0.0.1:3306/mydb?useSSL=false&useUnicode=true&characterEncoding=utf8
driver=com.mysql.jdbc.Driver
contexts=DEV
logLevel=info
liquibase.headless=true

And if all goes well, you should see something like:

####################################################
##   _     _             _ _                      ##
##  | |   (_)           (_) |                     ##
##  | |    _  __ _ _   _ _| |__   __ _ ___  ___   ##
##  | |   | |/ _` | | | | | '_ \ / _` / __|/ _ \  ##
##  | |___| | (_| | |_| | | |_) | (_| \__ \  __/  ##
##  \_____/_|\__, |\__,_|_|_.__/ \__,_|___/\___|  ##
##              | |                               ##
##              |_|                               ##
##                                                ##
##  Get documentation at docs.liquibase.com       ##
##  Get certified courses at learn.liquibase.com  ##
##  Free schema change activity reports at        ##
##      https://hub.liquibase.com                 ##
##                                                ##
####################################################
Starting Liquibase at 15:49:26 (version 4.17.0 #4922 built at 2022-10-05 14:56+0000)
Liquibase Version: 4.17.0
Liquibase Community 4.17.0 by Liquibase
Loading class `com.mysql.jdbc.Driver'. This is deprecated. The new driver class is `com.mysql.cj.jdbc.Driver'. The driver is automatically registered via the SPI and manual loading of the driver class is generally unnecessary.
...

Explanation

No further explanations seems necessary for this recipe.

Advertisement

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: