场景
DataX-阿里开源离线同步工具在Windows上实现Sqlserver到Mysql全量同步和增量同步:
https://blog.csdn.net/BADAO_LIUMANG_QIZHI/article/details/130330353
DataX-在Windows上实现postgresql同步数据到mysql:
https://blog.csdn.net/BADAO_LIUMANG_QIZHI/article/details/130410056
在上面的基础上如何进行多个Mysql到Mysql之间的数据同步。
注:
博客:
https://blog.csdn.net/badao_liumang_qizhi
实现
多个数据同步job就新建多个json文件,每个json文件中执行一次的job
比如第一个同步的json文件内容:
{ "job": { "content": [ { "reader": { "name": "mysqlreader", "parameter": { "column": [ "id", "location_number", "car_num", ], "connection": [ { "jdbcUrl": [ "jdbc:mysql://127.0.0.1:3306/数据库名?useUnicode=true&characterEncoding=gbk" ], "table": [ "表名" ] } ], "password": "密码", "username": "用户名", "where": "" } }, "writer": { "name": "mysqlwriter", "parameter": { "column": [ "id", "location_number", "car_num", ], "connection": [ { "jdbcUrl":"jdbc:mysql://127.0.0.1:3306/数据库名?useUnicode=true&characterEncoding=gbk", "table": [ "表名" ] } ], "password": "密码", "preSql": [ "delete from 表名" ], "session": [], "username": "用户名", "writeMode": "insert" } } } ], "setting": { "speed": { "channel": "5" } } } }
注意将数据库地址、名称、表名、列名、用户名、密码等改成自己对应。
然后再新建第二个数据同步的json文件
{ "job": { "content": [ { "reader": { "name": "mysqlreader", "parameter": { "column": [ "station_id", "station_number", "group_id", "mine_id", ], "connection": [ { "jdbcUrl": [ "jdbc:mysql://127.0.0.1:3306/数据库名?useUnicode=true&characterEncoding=gbk" ], "table": [ "表名" ] } ], "password": "密码", "username": "用户名", "where": "" } }, "writer": { "name": "mysqlwriter", "parameter": { "column": [ "station_id", "station_number", "group_id", "mine_id", ], "connection": [ { "jdbcUrl":"jdbc:mysql://127.0.0.1:3306/数据库名?useUnicode=true&characterEncoding=gbk", "table": [ "表名" ] } ], "password": "密码", "preSql": [ "delete from 表名" ], "session": [], "username": "root", "writeMode": "insert" } } } ], "setting": { "speed": { "channel": "5" } } } }
将此两个json文件放在datax的bin目录下
并在此目录下新建bat文件
#设置编码 chcp 65001 @echo off title "自定义标题" set INTERVAL=3600 timeout %INTERVAL% :Again python datax.py ./busCarInfoViewMysql2Mysql.json ping 127.0.0.1 -n 5 python datax.py ./tBaseStationMysql2Mysql.json echo %date% %time:~0,8% timeout %INTERVAL% goto Again
这里的3600就代表每3600秒执行一次。
ping 127.0.0.1 -n 5 目的是为了中间停顿5秒。
标签:同步,多个,Mysql,job,json,表名,id From: https://www.cnblogs.com/badaoliumangqizhi/p/17482211.html