1.Liquibase官網:https://www.liquibase.org/
2.支持所有主流數據庫
3.下載 https://github.com/liquibase/liquibase/releases/
4.環境搭建
4.1 如果沒安裝java,需要先安裝配置java環境
4.2 解壓縮zip包,把解壓后的根目錄添加到環境變量
5.創建一個新的目錄,放入以下三個文件
5.1 mysql-connector-java-8.0.17.jar
下載地址 https://repo.maven.apache.org/maven2/mysql/mysql-connector-java/8.0.17/mysql-connector-java-8.0.17.jar
5.2 liquibase.properties
driver: com.mysql.jdbc.Driver classpath: ./mysql-connector-java-8.0.17.jar url: jdbc:mysql://127.0.0.1:3307/test_liquibase?useUnicode=true&characterEncoding=UTF-8&serverTimezone=GMT%2B8&allowMultiQueries=true username: root password: root referenceDriver: com.mysql.jdbc.Driver referenceUrl: jdbc:mysql://127.0.0.1:3307/refrence_db?useUnicode=true&characterEncoding=UTF-8&serverTimezone=GMT%2B8&allowMultiQueries=true referenceUsername: root referencePassword: root
5.3 changelog-test.xml
文件基礎內容
<?xml version="1.0" encoding="UTF-8"?> <databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog/1.6" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog/1.6 http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-1.6.xsd"> </databaseChangeLog>
6 Liquibase基礎用法
6.1 生成數據庫結構文檔
在測試目錄下打開命令行,執行以下命令:
liquibase dbDoc C:/liquibase/doc --logLevel=error --changeLogFile=changelog-test.xml
命令執行完成后,會生成.html文件,用瀏覽器打開即可逐層查看數據庫結構
6.2 數據庫差異腳本生成
liquibase --changeLogFile="changeLogFiledevtest.xml" diffChangeLog // 先生成差異xml文件,然后使用命令轉化為差異sql文件
liquibase diffChangeLog updateSQL > update.sql // 注意liquibase.properties文件增加changeLogFile=changeLogFiledevtest.xml,可能會有錯誤,自行解決
6.3 使用差異更新數據庫
liquibase --changeLogFile="changeLogFiledevtest.xml" update
或者直接在數據庫中運行update.sql文件(推薦)
