MySQL表結構同步工具 mysql-schema-sync

來源:互聯網
上載者:User

標籤:

mysql-schema-sync 是一款使用go開發的、跨平台的、綠色無依賴的 MySQL 表結構自動同步工具。
用於將線上(其他環境)資料庫結構變化同步到測試(本地)環境!

可以解決多人開發,每人都使用獨立資料庫導致結構不一樣的問題!

支援功能:
1.  同步新表
2.  同步欄位 變動:新增、修改
3.  同步索引 變動:新增、修改
4.  同步欄位、索引 屏蔽變動更新
5.  支援預覽(只對比不同步變動)
6.  郵件通知變動結果 配置

參考 預設設定檔  config.json 配置同步源、目的地址。
修改郵件接收人  當運行失敗或者有表結構變化的時候你可以收到郵件通知。

預設情況不會對多出的表、欄位、索引刪除。若需要刪除欄位、索引 可以使用-drop參數。

配置樣本(config.json):

?

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

{

//source:同步源

"source":"test:[email protected](127.0.0.1:3306)/test_0",

//dest:待同步的資料庫

"dest":"test:[email protected](127.0.0.1:3306)/test_1",

//alter_ignore: 同步時忽略的欄位和索引

"alter_ignore":{

"tb1*":{

"column":["aaa","a*"],

"index":["aa"]

}

},

//  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 : 同步完成後發送郵件通知資訊 運行

?

1

2

3

4

5

#運行同步

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

#預覽並產生變更sql

mysql-schema-sync -conf mydb_conf.json 2>/dev/null >db_alter.sql 自動定時運行

添加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         mysql 同步源,eg [email protected](127.0.0.1:3306)/test_0   -drop         是否對本地多出的欄位和索引進行刪除 預設否   -source string         待同步的資料庫 eg: [email protected](10.10.0.1:3306)/test_1         該項不為空白時,忽略讀入 -conf參數項   -sync         是否將修改同步到資料庫中去,預設否   -tables string         待檢查同步的資料庫表,為空白則是全部         eg : product_base,order_*
 
來源:http://git.oschina.net/hidu/mysql-schema-sync

MySQL表結構同步工具 mysql-schema-sync

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.