1 Star 3 Fork 1

Woocan/mysql-sync

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
MIT

mysql-sync

MySQL Schema 自动同步工具
功能强大,用于命令行方式进行两个数据库之间的结构同步。同时支持对表进行表数据比较。

支持功能:

  1. 同步新表
  2. 同步字段 变动:新增、修改
  3. 同步索引 变动:新增、修改
  4. 同步存储过程
  5. 支持预览(只对比不同步变动)
  6. 对比数据差异
  7. 对比同一条sql语句在两个数据库中的执行结果
  8. 根据sql文件向目标库导入sql

配置示例(conf.json):

{
      // 同步源
      "source":"test:test@127.0.0.1:3306",
      //(可选)同步源在内网,支持ssh通道连接mysql,支持通过私钥连接ssh
      "source_ssh":"root:passwd123@14.xx.xx.xx:22",
      // 目标源
      "dest":"test:test@127.0.0.1:3308",
      //(可选)目标源在内网,支持ssh通道连接mysql,支持通过私钥连接ssh
      "dest_ssh":"root@14.xx.xx.xx:22/data/default.key",
      // 要处理的数据库名
      "schemas": ["game_config_db"],
      // 要检查的表,默认所有表,支持通配符
      "tables":[],
      // 要忽略的表,支持通配符
      "tables_ignore": [],
      // 要进行数据比较的表,会将内容存在差异的表名以注释的形式输出,注意查看
      "tables_compare_data":["sys_*"]
}

编译

go build -tags netgo -ldflags '-w -s -extldflags "-static"' -o sync.exe .\main.go

直接进行同步

sync.exe -conf conf.json -sync

生成变更sql

sync.exe -drop -conf conf.json >db_alter.sql

对比查询结果

sync.exe -conf conf.json -sql_check "select count(1) as cc from game_main_db.club"

导入sql文件到目标库

sync.exe -conf conf.json -sql_file ./data.sql

运行参数说明

sync.exe -help  
      -conf
            配置文件名称
      -drop
            是否对本地多出的字段和索引进行删除 默认否
      -sync
            是否将修改同步到数据库中去,默认否
      -sql_check
            检查sql语句在两个库的执行结果
      -sql_file
            导入sql文件到目标库
The MIT License (MIT) Copyright (c) 2015 du Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

简介

mysql数据库同步工具 展开 收起
README
MIT
取消

发行版 (1)

全部
10天前

贡献者

全部

近期动态

不能加载更多了
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/chrisx/mysql-sync.git
git@gitee.com:chrisx/mysql-sync.git
chrisx
mysql-sync
mysql-sync
master

搜索帮助