1、datax简述

DataX 是阿里巴巴集团内被广泛使用的离线数据同步工具/平台,实现包括 MySQL、Oracle、SqlServer、Postgre、HDFS、Hive、ADS、HBase、TableStore(OTS)、MaxCompute(ODPS)、DRDS 等各种异构数据源之间高效的数据同步功能。

2、datax在windows下的简单使用步骤

  在命令提示符界面进入datax\bin目录下,如CD E:\datax\bin

  用Python2执行此处为json文件的路径

  注意:必须使用Python2!!!!!!

  Python3会报以下错误:

  File "datax.py", line 114
    print readerRef
                  ^
SyntaxError: Missing parentheses in call to 'print'. Did you mean print(readerRef)?

 

  原因是python2的print在python3中变为了print()函数。

  因此可以安装python2,并用 py -2  来执行python代码,如:py -2 datax.py E:\New1.json 来执行python2的代码

  同理py -3执行python3的代码。   

 

3、datax简单示例参考(json文件)

  从CSV到MySQL数据库

 1 {
 2     "job": {
 3         "content": [
 4             {
 5                 "reader": {
 6                     "name": "txtfilereader", 
 7                     "parameter": {
 8                     "path": ["E:/Yi211.csv"], 
 9                     "encoding":"gbk",
10                         "column": [
11                             {
12                                 "index": 0,
13                                 "type": "string"
14                             },
15                             {
16                                 "index": 1,
17                                 "type": "string"
18                             },
19                             {
20                                 "index": 2,
21                                 "type": "string"
22                             },
23                             {
24                                 "index": 3,
25                                 "type": "string"
26                             },
27                             {
28                                 "index": 4,
29                                 "type": "string"
30                             },
31                             {
32                                 "index": 5,
33                                 "type": "string"
34                             },
35                         ],
36                     "fieldDelimiter":","
37                     }
38                 }, 
39                 "writer": {
40                     "name": "mysqlwriter", 
41                     "parameter": {
42                         "column": [
43                         "shengfen",
44                         "chengshi",
45                         "quezhen",
46                         "zhiyu",
47                         "siwang",
48                         "shijian"
49                         ], 
50                         "connection": [
51                             {
52                                 "jdbcUrl": "jdbc:mysql://localhost:3306/dbtest?useUnicode=true&characterEncoding=utf8", 
53                                 "table": ["yi211"]
54                             }
55                         ], 
56                         "password": "364624", 
57                         "username": "root",
58                         "preSql":[""],
59                         "session":["set session sql_mode='ANSI'"],
60                         "writeMode":"insert"
61                     }
62                 }
63             }
64         ], 
65         "setting": {
66             "speed": {
67                 "channel": "1"
68             }
69         }
70     }
71 }
View Code

相关文章: