使用datax将mongodb的数据同步到mysql
1、在不知道如何编写datax脚本的时候,可以先使用一下命令查看编写格式
[root@hadoop1 bin]# python datax.py -r streamreader -w streamwriter
这里将streamreader换成你想要的reader,将streamwriter换成相应的write即可
2、编写测试脚本
{
"job": {
"content": [
{
"reader": {
"name": "mongodbreader",
"parameter": {
"address": ["*************:27017"],
"collectionName": "mongo2mysql",
"column": [
{
"name":"name",
"type":"string"
},
{ "name":"age",
"type":"double"
},
{ "name":"gender",
"type":"string"
}
],
"dbName": "test"
}
},
"writer": {
"name": "mysqlwriter",
"parameter": {
"column": ["*"],
"connection": [
{
"jdbcUrl": "jdbc:mysql://*************:3306/datax",
"table": ["test"]
}
],
"password": "*******",
"username": "root",
"writeMode": "insert"
}
}
}
],
"setting": {
"speed": {
"channel": "1"
}
}
}
}
3、编写完成后需要启动脚本,启动语法如下:
[root@hadoop1 bin]# python datax.py /opt/datax/job/test.json
4、输出结果如下: