美文网首页
MySQL表导入hive表(一次性导入,增量导入)

MySQL表导入hive表(一次性导入,增量导入)

作者: 府学路十八吖 | 来源:发表于2018-11-25 16:27 被阅读0次

    前言

    如何实现将数据从MySQL表中导入hive表中,我在这里使用sqoop实现了数据导入,以下是完整的脚本实例,分别是一次性导入示例和增量导入示例。

    脚本示例

    hive中建立外部表,实现从MySQL表中导入数据到集群hive表中(一次性导入)

    #!/bin/sh
    sqoop import \
    --hive-import \
    --connect jdbc:mysql://10.62.20.180:3306/userInformation \
    --username root \
    --password 123789 \
    --query "select user_id, gender, name, age, occupation, speciality from user_table where user_id is not null and \$CONDITIONS" \
    --target-dir 'user/hive/warehouse/test/user_table' \
    --split-by date \
    --fields-terminated-by "\t" \
    --hive-table user_table

    hive中建立外部表,实现从MySQL中增量导入数据到hive表中(增量导入)

    #!/bin/bash
    sqoop import \
    --hive-import \
    --connect jdbc:mysql://10.62.20.180:3306/userInformation \
    --username root \
    --password 123789 \
    --query "select user_id, gender, name, age, occupation, speciality, start_time from user_table where start_time between '2018-11-1' and '2018-11-12' and \$CONDITIONS" \
    --target-dir '/user/hive/warehouse/default.db/mysqlToHive' \
    --split-by car_id \
    --hive-table mysqlToHive \
    --incremental append \
    --check-column start_time \
    --fields-terminated-by "\t"

    check-column:指定原表中用来做增量判断条件的字段

    incremental lastmodified:指定的增量模式,append或者lastmodified

    如果想要增量的从MySQL表中导入数据到hive表中,首先需要使用脚本一建立一张基础表,然后再通过脚本二实现数据的增量导入

    相关文章

      网友评论

          本文标题:MySQL表导入hive表(一次性导入,增量导入)

          本文链接:https://www.haomeiwen.com/subject/gcbpqqtx.html