读取MongoDB的数据导入MySQL
1)在MySQL中创建表
mysql> create table jason(name varchar(20),url varchar(20));
2)编写DataX配置文件
[jason@hadoop102 datax]$ vim job/mongodb2mysql.json { "job": { "content": [ { "reader": { "name": "mongodbreader", "parameter": { "address": ["127.0.0.1:27017"], "collectionName": "jason", "column": [ { "name":"name", "type":"string" }, { "name":"url", "type":"string" } ], "dbName": "test", } }, "writer": { "name": "mysqlwriter", "parameter": { "column": ["*"], "connection": [ { "jdbcUrl": "jdbc:mysql://hadoop102:3306/test", "table": ["jason"] } ], "password": "000000", "username": "root", "writeMode": "insert" } } } ], "setting": { "speed": { "channel": "1" } } } }
3)执行
[jason@hadoop102 datax]$ bin/datax.py job/mongodb2mysql.json
4)查看结果
mysql> select * from jason; +---------+-----------------+ | name | url | +---------+-----------------+ | jason | www.jason.com | +---------+-----------------+