GithubHelp home page GithubHelp logo

fortitudepub / mysql-schema-sync Goto Github PK

View Code? Open in Web Editor NEW

This project forked from hidu/mysql-schema-sync

0.0 1.0 0.0 147 KB

mysql表结构自动同步工具(目前只支持字段、索引的同步,分区等高级功能暂不支持)

License: MIT License

Shell 0.82% Go 99.18%

mysql-schema-sync's Introduction

mysql-schema-sync

mysql表结构自动同步工具

用于将 线上 数据库结构变化同步到 本地环境!
支持功能:

  1. 同步新表
  2. 同步字段 变动:新增、修改
  3. 同步索引 变动:新增、修改
  4. 支持预览(只对比不同步变动)
  5. 邮件通知变动结果
  6. 支持屏蔽更新表、字段、索引、外键
  7. 支持本地比线上额外多一些表、字段、索引、外键

安装

go get -u github.com/hidu/mysql-schema-sync

配置

参考 默认配置文件 config.json 配置同步源、目的地址。
修改邮件接收人 当运行失败或者有表结构变化的时候你可以收到邮件通知。

默认情况不会对多出的表、字段、索引、外键删除。若需要删除字段、索引、外键 可以使用 -drop 参数。

配置示例(config.json):

{
      //source:同步源
      "source":"test:test@(127.0.0.1:3306)/test_0",
      //dest:待同步的数据库
      "dest":"test:test@(127.0.0.1:3306)/test_1",
      //alter_ignore: 同步时忽略的字段和索引
      "alter_ignore":{
        "tb1*":{
            "column":["aaa","a*"],
            "index":["aa"],
            "foreign":[]
        }
      },
      //  tables: table to check schema,default is all.eg :["order_*","goods"]
      "tables":[],
      //有变动或者失败时,邮件接收人
      "email":{
          "send_mail":false,
         "smtp_host":"smtp.163.com:25",
         "from":"[email protected]",
         "password":"xxx",
         "to":"[email protected]"
      }
}

json配置项说明

source: 数据库同步源
dest: 待同步的数据库
tables: 数组,配置需要同步的表,为空则是不限制,eg: ["goods","order_*"]
alter_ignore: 忽略修改的配置,表名为tableName,可以配置 column 和 index,支持通配符 *
email : 同步完成后发送邮件通知信息

运行

直接运行

mysql-schema-sync -conf mydb_conf.json -sync

预览并生成变更sql

mysql-schema-sync -conf mydb_conf.json 2>/dev/null >db_alter.sql

使用shell调度

bash check.sh

每个json文件配置一个目的数据库,check.sh脚本会依次运行每份配置。 log存储在当前的log目录中。

自动定时运行

添加crontab 任务

30 * * * * cd /your/path/xxx/ && bash check.sh >/dev/null 2>&1

参数说明

mysql-schema-sync [-conf] [-dest] [-source] [-sync] [-drop]

说明:


# mysql-schema-sync -help  
  -conf string
        配置文件名称
  -dest string
        待同步的数据库 eg: test@(10.10.0.1:3306)/test_1
        该项不为空时,忽略读入 -conf参数项
  -drop
        是否对本地多出的字段和索引进行删除 默认否
  -source string
        mysql 同步源,eg test@(127.0.0.1:3306)/test_0
  -sync
        是否将修改同步到数据库中去,默认否
  -tables string
        待检查同步的数据库表,为空则是全部
        eg : product_base,order_*


mysql-schema-sync's People

Contributors

hidu avatar 514366607 avatar bryant1410 avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.