基于湖库一体架构,统一管理结构化、半结构化与非结构化等多模态数据,一个系统承载事务处理、实时分析与 AI 工作负载。
通过 Liquibase 管理 OceanBase 数据库版本
更新时间:2026-06-01 11:19:14
Liquibase 是一个开源的数据库版本控制工具,它支持数据库的版本追踪、更新以及回滚。
前提条件
- 下载 Liquibase 并解压安装。
- 从官方网站下载 MySQL JDBC 驱动,获得
mysql-connector-j-x.x.x.jar文件。
使用示例
将下载的
mysql-connector-j-x.x.x.jar放入 Liquibase 的 lib 目录下。新建 liquibase.properties配置文件,写入以下内容:
url: jdbc:mysql://x.x.x.x:3306/test username: username password: ***** classpath: lib/mysql-connector-j-8.3.0.jar执行以下 liquibase 命令,生成数据库当前结构状态的快照。注意,根据版本不同,实际参数可能有所区别,请参考官方文档。
./liquibase --changeLogFile=mydatabase_changelog.xml generateChangeLog
4.创建新的表,新建 dbchangelog.xml 文件,写入以下内容。
```xml
<?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"
xmlns:pro="http://www.liquibase.org/xml/ns/pro"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-4.4.xsd
http://www.liquibase.org/xml/ns/pro http://www.liquibase.org/xml/ns/pro/liquibase-pro-4.5.xsd">
<changeSet author="BobR" id="myIDNumber123">
<createTable tableName="actor">
<column autoIncrement="true" name="id" type="INTEGER">
<constraints nullable="false" primaryKey="true" primaryKeyName="actor_pkey"/>
</column>
<column name="firstname" type="VARCHAR(255)"/>
<column name="lastname" type="VARCHAR(255)"/>
<column name="twitter" type="VARCHAR(15)"/>
</createTable>
</changeSet>
</databaseChangeLog>
```
- 上述配置描述一个创建actor表的变更,现在执行变更。
./liquibase update --changeLogFile=dbchangelog.xml - 变更成功后,也可以尝试执行回滚操作,回退到上个版本。
./liquibase rollbackCount 1 --changelog-file=dbchangelog.xml