执行环境python3.7 , datax3.0, windows10,mysql8.0.27
一、获取job.json样本
python D:\dataxTest\datax\bin\datax.py -r mysqlreader -w mysqlwriter > mysqlTomysql.json
mysqlTomysql.json配置如下
{
"job": {
"content": [
{
"reader": {
"name": "mysqlreader",
"parameter": {
"column": ["id","lable","lable2","lable3","lable4"],
"connection": [
{
"jdbcUrl": ["jdbc:mysql://IP:端口/datax?useSSL=false&useUnicode=true&characterEncoding=utf8&serverTimezone=UTC"],
"table": ["datax_fdl"]
}
],
"password": "root",
"username": "root",
"where": "id > 3"
}
},
"writer": {
"name": "mysqlwriter",
"parameter": {
"column": ["id","lable","lable2","lable3","lable4"],
"connection": [
{
"jdbcUrl": "jdbc:mysql://IP:端口/datax?useSSL=false&useUnicode=true&characterEncoding=utf8&serverTimezone=UTC",
"table": ["datax_fdl_4"]
}
],
"password": "root",
"preSql": ["delete from datax_fdl_4 "],
"session": [],
"username": "root",
"writeMode": "insert"
}
}
}
],
"setting": {
"speed": {
"channel": "2"
}
}
}
}
mysql 表结构
-- 原始表
CREATE TABLE datax_fdl (
id bigint NOT NULL AUTO_INCREMENT
,lable varchar(200) DEFAULT NULL
,lable2 varchar(200) DEFAULT NULL
,lable3 varchar(200) DEFAULT NULL
,lable4 varchar(200) DEFAULT NULL
,create_time timestamp NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间'
,update_time timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间'
,PRIMARY KEY (id)
) DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
-- 待插入结果表
create table datax_fdl_4 like datax_fdl;
- 执行语句
D:\file_app\Anaconda\python.exe D:\dataxTest\datax\bin\datax.py D:\dataxTest\workJson\mysqlTomysql.json
- 配置项参数
1.mysqlreader的where 配置: 条件必须为column内列出来的字段名,否则不生效
2.mysqlwriter的writeMode配置
均根据主键ID判断是否更新
replace 重新写入,原有删除
update 有更新才会变化,无更新不做操作
insert 主键已存在数据判断为脏数据,新增数据不影响
3.mysqlwrite的preSql 可配值导入前对目标表的操作, 注意写入模式insert的区别,重复写入结果不一样
delete from datzx_fdl_4
或者 update datax_fdl_4 set lable=111 where id > 1
网友评论