datax MySql --> Hive实现

配置文件

{
    "job": {
        "setting": {
            "speed": {
                "channel":3
            },
            "errorLimit": {
                "record": 0,
                "percentage": 0.02
            }
        },
        "content": [
            {
                "reader": {
                    "name": "mysqlreader",
                    "parameter": {
                        "username": "root",
                        "password": "123456",
                        "column": [
                            "id",
                            "name",
                            "age",
                            "sex",
                            "clazz"
                        ],
                        "splitPk": "id",
                        "connection": [
                            {
                                "table": [
                                    "students"
                                ],
                                "jdbcUrl": [
     "jdbc:mysql://master:3306/bigdata"
                                ]
                            }
                        ]
                    }
                },
                "writer": {
                    "name": "hdfswriter",
                    "parameter": {
                        "defaultFS": "hdfs://master:9000",
                        "fileType": "text",
                        "path": "/user/hive/warehouse/bigdata32.db/students",
                        "fileName": "students",
                        "column": [
                            {
                                "name": "id",
                                "type": "INT"
                            },
                            {
                                "name": "name",
                                "type": "string"
                            },
                            {
                                "name": "age",
                                "type": "INT"
                            },
                            {
                                "name": "sex",
                                "type": "string"
                            },
                            {
                                "name": "clazz",
                                "type": "string"
                            }
                        ],
                        "writeMode": "append",
                        "fieldDelimiter": ","
                        
                    }
                }
            }
        ]
    }
}

hive 建表

create table IF NOT EXISTS students
(
    id bigint,
    name string,
    age int,
    sex string,
    clazz string
)
ROW FORMAT DELIMITED FIELDS TERMINATED BY ',';

表路径

vim MySQLToHive.json
datax.py MySQLToHive.json

成功

posted @ 2024-11-27 21:10  w我自横刀向天笑  阅读(4)  评论(0编辑  收藏  举报