这是一个MySQL迁移工具。
支持模块TableViewFunctionProcedureTrigger使用方法引入jar包:
<dependency><groupId>cn.codeforfun</groupId><artifactId>mysql-migrate</artifactId><version>1.0.0</version></dependency>测试方法:
importcn.codeforfun.migrate.core.diff.DiffResult;importcn.codeforfun.migrate.core.entity.DatabaseInfo;importorg.junit.Test;importjava.sql.SQLException;importjava.util.List;privatestaticfinalIntegerFROM_PORT=3306;privatestaticfinalStringFROM_HOST="localhost";privatestaticfinalStringFROM_USERNAME="root";privatestaticfinalStringFROM_PASSWORD="root";privatestaticfinalStringFROM_TABLE="test_db";privatestaticfinalIntegerTO_PORT=3307;privatestaticfinalStringTO_HOST="localhost";privatestaticfinalStringTO_USERNAME="root";privatestaticfinalStringTO_PASSWORD="root";privatestaticfinalStringTO_TABLE="test_db";@Testpublicvoiddiff()throwsSQLException{DatabaseInfofrom=newDatabaseInfo(FROM_HOST,FROM_PORT,FROM_TABLE,FROM_USERNAME,FROM_PASSWORD);DatabaseInfoto=newDatabaseInfo(TO_HOST,TO_PORT,TO_TABLE,TO_USERNAME,TO_PASSWORD);Migratemigrate=newMigrate().from(from).to(to);DiffResultdiffResult=migrate.diff();List<String>sqlList=diffResult.getSqlList();for(Stringsql:sqlList){System.out.println(sql);}}@Testpublicvoidupdate()throwsSQLException{DatabaseInfofrom=newDatabaseInfo(FROM_HOST,FROM_PORT,FROM_TABLE,FROM_USERNAME,FROM_PASSWORD);DatabaseInfoto=newDatabaseInfo(TO_HOST,TO_PORT,TO_TABLE,TO_USERNAME,TO_PASSWORD);Migratemigrate=newMigrate().from(from).to(to);migrate.update();}源码地址Gitee仓库
Github仓库
评论