# mysqlSync **Repository Path**: vimda2/mysqlSync ## Basic Information - **Project Name**: mysqlSync - **Description**: mysql数据库表结构同步 - **Primary Language**: Java - **License**: MIT - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 7 - **Forks**: 2 - **Created**: 2019-04-02 - **Last Updated**: 2022-11-23 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README ## 注意 同步两张表之间的表结构。 模仿navict中同步数据库功能。 适合于开发和测试环境之间同步表结构使用 ,修改表结构会导致数据丢失。 生产环境慎用,单纯添加表、字段、索引不受影响。 **删除字段** ```sql SET FOREIGN_KEY_CHECKS = 0; alter table `portal_name` DROP COLUMN `name`; alter table `portal_name` DROP COLUMN `age`; SET FOREIGN_KEY_CHECKS = 1; ``` # 参考并改自:https://gitee.com/alchemystar/Lancer # mysqlSync 同步两个DB之间的schema,配置如下: sourceHost=127.0.0.1:3306 sourceUser=root sourcePass=123123123 sourceSchema=temp_db sourceCharset=utf8 targetHost=127.0.0.1:3306 targetUser=root targetPass=123123123 targetSchema=temp_test targetCharset=utf8 autoExecute=YES //此处表明自动同步 原理: 通过捞取information_schema来比较source_schema和target_schema(可在不同实例)的表结构是否一致, 如果target_schema没有则这张表则创建, 如果target_schema表里面没有这个字段则alter add(保证顺序), 如果表里面有这个字段、但属性不一样则alter change, 另外还同步索引的元数据.