一、数据表:
CREATE TABLE `products` (`Id` varchar(50) NOT NULL,`Name` varchar(50) DEFAULT NULL,`Addrress` longtext,`RowVersion` timestamp(6) NULL DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6),`CreateTime` datetime(6) NOT NULL,`UpdateTime` datetime(6) NOT NULL,`ExtraProperties` longtext,PRIMARY KEY (`Id`)) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;CREATE TABLE `products2` (`Id` varchar(50) NOT NULL,`Name` varchar(50) DEFAULT NULL,`Addrress` longtext,`CreateTime` datetime(6) NOT NULL,`UpdateTime` datetime(6) NOT NULL) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
二、新建任务:demo2
此处的关键点在${lastTime},${currentTime},
${}是DataX动态参数的固定格式,lastTime,currentTime就是我们页面配置中
-DlastTime=’%s’ -DcurrentTime=’%s’
select Id,Name,Addrress,CreateTime,UpdateTime from products where UpdateTime >= ${lastTime} and UpdateTime < ${currentTime}
{"job": {"setting": {"speed": {"channel": 3,"byte": 1048576},"errorLimit": {"record": 0,"percentage": 0.02}},"content": [{"reader": {"name": "mysqlreader","parameter": {"username": "==","password": "==","splitPk": "Id","connection": [{"querySql": ["select Id,Name,Addrress,CreateTime,UpdateTime from products where UpdateTime >= ${lastTime} and UpdateTime < ${currentTime} "],"jdbcUrl": ["jdbc:mysql://192.168.31.132:3306/demo"]}]}},"writer": {"name": "mysqlwriter","parameter": {"username": "==","password": "==","writeMode": "update","column": ["`Id`","`Name`","`Addrress`","`CreateTime`","`UpdateTime`"],"connection": [{"table": ["products2"],"jdbcUrl": "jdbc:mysql://192.168.31.132:3306/demo"}]}}}]}}