DataX将MySql数据库数据同步到Oracle数据库
DataX/userGuid.md at master · alibaba/DataX (github.com)
job文件夹下存放数据同步的json脚本
{ "job": { "setting": { "speed": { "channel": 1 } }, "content": [ { "reader": { "name": "mysqlreader", "parameter": { "username": "${readUsername}", "password": "${readPassword}", "column": [ "CreateTime","Id","OrderNum","IsDelete","IsLock" ], "connection": [ { "table": [ "table1" ], "jdbcUrl": [ "jdbc:mysql://${readJdbcUrl}?useUnicode=true&characterEncoding=utf-8&useSSL=false" ] } ] } }, "writer": { "name": "oraclewriter", "parameter": { "username": "${writeUsername}", "password": "${writePassword}", "column": [ "CREATETIME","ID","ORDER_NUM","IS_DELETE","IS_LOCK" ], "connection": [ { "jdbcUrl": "jdbc:oracle:thin:@${writeJdbcUrl}", "table": [ "Table1" ] } ] } },
"transformer":[ //处理Mysql Bool类型到Oracle
{
"name":"dx_groovy",
"parameter":{
"code":"def indexList = [3,4]; for (index in indexList) {Column column = record.getColumn(index); String oriValue = column.asString(); if ('true'.equals(oriValue)) {String newValue = oriValue.replace('true', '1'); record.setColumn(index, new StringColumn(newValue));}; if ('false'.equals(oriValue)) {String newValue = oriValue.replace('false', '0'); record.setColumn(index, new StringColumn(newValue));}}; return record;",
"extraPackage":[]
}
}
]
} ] } } python D:\datax\bin\datax.py D:\datax\table1_job.json -p "-DreadJdbcUrl=127.0.0.1:3306/testdb -DreadUsername=root -DreadPassword=123456 -DwriteJdbcUrl=127.0.0.1:1521:TestDB -DwriteUsername=yonghuming -DwritePassword=mima"
{ "job": { "setting": { "speed": { "channel": 1, "byte": 1048576 }, "errorLimit": { "record": 0, "percentage": 0.02 } }, "content": [ { "reader": { "name": "mysqlreader", "parameter": { "username": "root", "password": "123456", "column": [ "Id" ], "where": "", "splitPk": "", "connection": [ { "table": [ "testtb" ], "jdbcUrl": [ "jdbc:mysql://127.0.0.1:3306/testdb" ] } ] } }, "writer": { "name": "oraclewriter", "parameter": { "username": "yonghuming", "password": "mima", "writeMode": "insert", "column": [ "Id" ], "connection": [ { "table": [ "testtb1" ], "jdbcUrl": "jdbc:oracle:thin:127.0.0.1:1521:TestDB" } ] } } } ] } }
python D:\datax\bin\datax.py D:\datax\table1_job.json
DataX在windows下中文乱码问题修复
临时解决方法为:再打开的命令提示符终端窗口输入chcp 65001
长久解决办法为:regedit打开注册表,找到HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Command Processor 右键新建字符串,