datax下载地址:https://github.com/alibaba/DataX
下载完后解压,然后自己写json文件,或者去https://github.com/alibaba/DataX/blob/master/introduction.md里面找现成的进行修改。
json文件格式:(以本地文档到数据库为例)
{ "job": { "content":[ { "reader": { "name": "txtfilereader", "parameter": { "path":["源文件路径"], "encoding":"gbk", "column": [ { "index":0, "type":"string" }, { "index":1, "type":"string" } ], "fileldDelimiter":"分隔符" } }, "writer": { "name": "mysqlwriter", "parameter": { "username": "账户", "password": "密码", "column": [ "列名1", "列名2" ], "preSql": [], "connection": [ { "jdbcUrl": "jdbc:mysql://ip:3306/数据库名", "table": ["数据表名"] } ] } } } ], "setting": { "speed": { "channel": "1" } } } }
之后进入cmd,进入datax中的bin目录下,输入命令:python2 datax.px js文件路径
数据库导入成功!
注:
1、python版本为2,不可为3(因为python3的print语句发生变化)
2、数据库中的数据中文乱码解决:在json文件中jdbcUrl项加上:?characterEncoding=utf8