标签:datax git bat lap datetime 线数据 oca tor 简单
DataX 是阿里巴巴集团内被广泛使用的离线数据同步工具/平台,实现包括 MySQL、Oracle、SqlServer、Postgre、HDFS、Hive、ADS、HBase、TableStore(OTS)、MaxCompute(ODPS)、DRDS 等各种异构数据源之间高效的数据同步功能。
在命令提示符界面进入datax\bin目录下,如CD E:\datax\bin
用Python2执行此处为json文件的路径
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的代码。
从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 }
这里给出MySQL到MySQL数据库的部分json文件,与上部分同理。
1 { 2 "job": { 3 "content": [ 4 { 5 "reader": { 6 "name": "mysqlreader", 7 "parameter": { 8 "column": ["id","name","num"], 9 "connection": [ 10 { 11 "jdbcUrl": ["jdbc:mysql://localhost:3306/dbtest?useUnicode=true&characterEncoding=utf8&yearIsDateType=false&zeroDateTimeBehavior=convertToNull&tinyInt1isBit=false&rewriteBatchedStatements=true"], 12 "table": ["test1"] 13 } 14 ], 15 "password": "364624", 16 "username": "root", 17 18 } 19 }, 20 "writer": { 21 "name": "mysqlwriter", 22 "parameter": { 23 "column": ["id","name","num"], 24 "connection": [ 25 { 26 27 "jdbcUrl": "jdbc:mysql://localhost:3306/dbtest", 28 "table": ["test2"] 29 } 30 ], 31 "password": "364624", 32 "username": "root", 33 } 34 } 35 } 36 ], 37 "setting": { 38 "speed": { 39 "channel": 1 40 } 41 } 42 } 43 }
json文件格式错误:
经DataX智能分析,该任务最可能的错误原因是:
com.alibaba.datax.common.exception.DataXException: Code:[Common-00], Describe:[您提供的配置文件存在错误信息,请检查您的作业配置 .] - 配置信息错误. 您提供的配置信息不是合法的JSON格式: unclosed string : * . 请按照标准json格式提供配置信息.
命令提示符界面出现出现乱码:
可以在cmd中输入: CHCP 65001 ,然后进行后续操作。
py -2 datax.py E:\New1.json
标签:datax git bat lap datetime 线数据 oca tor 简单
原文地址:https://www.cnblogs.com/zlc364624/p/12374089.html