DataX
DataX 是阿里巴巴集团内被广泛使用的离线数据同步工具/平台,实现包括 MySQL、Oracle、SqlServer、Postgre、HDFS、Hive、ADS、HBase、TableStore(OTS)、MaxCompute(ODPS)、DRDS 等各种异构数据源之间高效的数据同步功能。
DataXgit地址
安装
直接下载DataX工具包:
DataX下载地址
下载后解压至本地某个目录,进入bin目录,即可运行同步作业:
shell cd {YOUR_DATAX_HOME}/bin python datax.py {YOUR_JOB.json}
自检脚本:
python {YOUR_DATAX_HOME}/bin/datax.py {YOUR_DATAX_HOME}/job/job.json
使用
1.生成job.json的示例文件
cd {YOUR_DATAX_HOME}/bin
python datax.py -r mysqlreader -w postgresqlwriter
会生成实例文件
2.将实例文件复制到.json文件里。修改里面的配置项,实例json文件如下所示:
{
"job": {
"content": [
{
"reader": {
"name": "mysqlreader",
"parameter": {
"column": ["id" , "fid" , "name" , "type" , "ab"],
"connection": [
{
"jdbcUrl": ["jdbc:mysql://192.168.0.111:3306/etl"],
"table": ["district"]
}
],
"password": "root",
"username": "root",
"where": ""
}
},
"writer": {
"name": "postgresqlwriter",
"parameter": {
"column": ["id" , "fid" , "name" , "type" , "ab"],
"connection": [
{
"jdbcUrl": "jdbc:postgresql://192.168.0.111:5432/etl",
"table": ["district"]
}
],
"password": "root",
"postSql": [],
"preSql": [],
"username": "postgres"
}
}
}
],
"setting": {
"speed": {
"channel": 5
}
}
}
}
须知
- DataX没法同步表结构,因此在同步数据时,必须保证writer里的表已经存在。
- column字段最好不要用“*”代替,保证需要同步什么字段就写什么字段。WARN:您的配置文件中的列配置存在一定的风险. 因为您未配置读取数据库表的列,当您的表字段个数、类型有变动时,可能影响任务正确性甚至会运行出错。
- 通常不建议写入数据库时,通道个数 > 32
版权声明:本文为u013705066原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。