【DataX 增量同步】读取Mysql数据到HDFS

如果是第一次操作的同学不知道的可以看我之前写的博客,操作过一次后面基本是相同的了

在目录三:https://blog.csdn.net/Zsigner/article/details/108362724

1、生成hdfswriter plugins 修改pom.xml

//原始的里面是所有很全的,不过一般都是按需install
   <modules>
        <module>common</module>
        <module>core</module>
        <module>transformer</module>
 
        <!-- reader -->
        <module>mysqlreader</module>
        
 
        <!-- writer -->
       
        <module>hdfswriter</module>
        
 
        <!-- common support module -->
        <module>plugin-rdbms-util</module>
        <module>plugin-unstructured-storage-util</module>
        <module>hbase20xsqlreader</module>
        <module>hbase20xsqlwriter</module>
    </modules>


2、编译生成elasticsearchwriter 插件

mvn clean install -Dmaven.test.skip=true


3、复制生成的文件到 /datax/plugin/,注意区分reader 跟writer

cp -r /usr/local/DataX-master/hdfswriter/target/datax/plugin/writer/hdfswriter /usr/local/data/datax/datax/plugin/writer

4、编写脚本 test.json

{
  "job": {
    "setting": {
      "speed": {
        "channel": 1
      }
    },
    "content": [
      {
        "reader": {
          "name": "mysqlreader",
          "parameter": {
            "username": "datax",
            "password": "123456",
            "where": "updated_at>='${start_time}' and updated_at<='${end_time}'",
            "column": [
              "app_id",
              "created_at",
              "id",
              "in_id",
              "is_deleted",
              "resource_id"
            ],
            "connection": [
              {
                "jdbcUrl": [
                  "jdbc:mysql://127.0.0.1:3306/test?com.mysql.jdbc.faultInjection.serverCharsetIndex=45"
                ],
                "table": [
                  "test"
                ]
              }
            ]
          }
        },
        "writer": {
          "name": "hdfswriter",
          "parameter": {
            "defaultFS": "hdfs://127.0.0.1:4007",
            "fileType": "orc",
            "path": "/usr/hive/warehouse/db/test/statdate=${statdate}",
            "fileName": "part-m-",
            "column": [
              {
                "name": "app_id",
                "type": "String"
              },
              {
                "name": "created_at",
                "type": "String"
              },
              {
                "name": "id",
                "type": "int"
              },
              {
                "name": "in_id",
                "type": "String"
              },
              {
                "name": "is_deleted",
                "type": "int"
              },
              {
                "name": "resource_id",
                "type": "String"
              }
            ],
            "writeMode": "append",
            "fieldDelimiter": "\u0001",
            "compress":"NONE"
          }
        }
      }
    ]
  }
}

5、运行脚本

python /usr/local/datax/bin/datax.py ./test.json -p "-Dstart_time=2020-09-05 -Dend_time=2020-09-05"

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Zsigner

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值