lmmtMySQL 迁移工具

联合创作 · 2023-09-30 23:48

这是一个MySQL迁移工具。

支持模块

  • Table
  • View
  • Function
  • Procedure
  • Trigger

使用方法

引入jar包:

<dependency>
  <groupId>cn.codeforfun</groupId>
  <artifactId>mysql-migrate</artifactId>
  <version>1.0.0</version>
</dependency>

测试方法:

import cn.codeforfun.migrate.core.diff.DiffResult;
import cn.codeforfun.migrate.core.entity.DatabaseInfo;
import org.junit.Test;

import java.sql.SQLException;
import java.util.List;

private static final Integer FROM_PORT = 3306;
private static final String FROM_HOST = "localhost";
private static final String FROM_USERNAME = "root";
private static final String FROM_PASSWORD = "root";
private static final String FROM_TABLE = "test_db";

private static final Integer TO_PORT = 3307;
private static final String TO_HOST = "localhost";
private static final String TO_USERNAME = "root";
private static final String TO_PASSWORD = "root";
private static final String TO_TABLE = "test_db";

@Test
public void diff() throws SQLException {
    DatabaseInfo from = new DatabaseInfo(FROM_HOST, FROM_PORT, FROM_TABLE, FROM_USERNAME, FROM_PASSWORD);
    DatabaseInfo to = new DatabaseInfo(TO_HOST, TO_PORT, TO_TABLE, TO_USERNAME, TO_PASSWORD);
    Migrate migrate = new Migrate().from(from).to(to);
    DiffResult diffResult = migrate.diff();
    List<String> sqlList = diffResult.getSqlList();
    for (String sql : sqlList) {
        System.out.println(sql);
    }
}

@Test
public void update() throws SQLException {
    DatabaseInfo from = new DatabaseInfo(FROM_HOST, FROM_PORT, FROM_TABLE, FROM_USERNAME, FROM_PASSWORD);
    DatabaseInfo to = new DatabaseInfo(TO_HOST, TO_PORT, TO_TABLE, TO_USERNAME, TO_PASSWORD);
    Migrate migrate = new Migrate().from(from).to(to);
    migrate.update();
}

源码地址

Gitee仓库

Github仓库

浏览 6
点赞
评论
收藏
分享

手机扫一扫分享

编辑 分享
举报
评论
图片
表情
推荐
点赞
评论
收藏
分享

手机扫一扫分享

编辑 分享
举报