1、环境准备
JDK1.8
Python2.6+(一定要python2)
DataX(点击下载 Datax下载地址:http://datax-opensource.oss-cn-hangzhou.aliyuncs.com/datax.tar.gz点击下载)
2、配置
2.1 DataX存放路径
2.1 Data的Job mysql2mysql.json
{
"job": {
"content": [
{
"reader": {
"name": "mysqlreader",
"parameter": {
"column": [
"id",
"name",
"password"
],
"connection": [
{
"jdbcUrl": ["jdbc:mysql://127.0.0.1:3306/datax_r"],
"table": ["t_user"]
}
],
"password": "root",
"username": "root"
}
},
"writer": {
"name": "mysqlwriter",
"parameter": {
"column": [
"id",
"name",
"password"
],
"connection": [
{
"jdbcUrl": "jdbc:mysql://127.0.0.1:3306/datax_w",
"table": ["t_user"]
}
],
"password": "root",
"username": "root"
}
}
}
],
"setting": {
"speed": {
"channel": "1"
}
}
}
}
存放路径:D:\mysql2mysql.json
3、启动
1、python命令启动
python D:\datax\bin\datax.py D:\mysql2mysql.json
2、Java启动
import com.alibaba.datax.core.Engine;
import lombok.extern.slf4j.Slf4j;
import java.text.SimpleDateFormat;
import java.util.Date;
@Slf4j
public class TestDatax {
public static void main(String[] args) throws Throwable {
String dataxPath = "D:\\datax\\";
String jsonPath = "D:\\mysql2mysql.json";
System.setProperty("datax.home", dataxPath);
System.setProperty("now", new SimpleDateFormat("yyyy/MM/dd-HH:mm:ss:SSS").format(new Date()));// 替换job中的占位符
//String[] datxArgs = {"-job", dataxPath + "/job/text.json", "-mode", "standalone", "-jobid", "-1"};
String[] datxArgs = {"-job", jsonPath, "-mode", "standalone", "-jobid", "-1"};
Engine.entry(datxArgs);
}
}