大数据同步技术datax安装链接https://github.com/alibaba/DataX
配置 python2,jdk1.8
第一步命令查看配置模板:
cd D:\DataX\datax\bin d: python2 datax.py -r mysqlreader -w mysqlwriter
json模板
{ "job": { "setting": { "speed": { "channel": 1 } }, "content": [ { "reader": { "name": "txtfilereader", "parameter": { "path": ["F:/作业.txt"],//文本路径 "encoding": "gbk", "column": [//文本列 { "index": 0, "type": "string" }, { "index": 1, "type": "string" } ], "fieldDelimiter": ",",//文件分隔符号 "skipHeader": "true" } }, "writer": { "name": "mysqlwriter", "parameter": { "writeMode": "insert", "username": "root", "password": "199126", "column": [//表里字段 "time", "name", ], "session": [], "connection": [ { "jdbcUrl": "jdbc:mysql://127.0.0.1:3306/kettle?useUnicode=true&characterEncoding=utf8&useSSL=false", //数据库路径 "table": ["my"]//数据库表 } ] } } } ] } }
数据库里建好表后
启动datax 将文件导入数据库里
将python2 D:\DataX\datax\bin\datax.py F:\json.json
出现的问题:
- Python版本要为2,原因前面已经说过了
- cmd乱码解决:输入CHCP 65001
- 数据库中的数据中文乱码解决:在json文件中jdbcUrl项加上:?characterEncoding=utf8