zoukankan      html  css  js  c++  java
  • Sqoop 导入及导出表数据子集命令详解

    Sqoop命令详解

           1、import命令

    案例1:将mysql表test中的数据导入hive的hivetest表,hive的hivetest表不存在。

          


    sqoop import --connect jdbc:mysql://hadoop-001:3306/test --username root --password 123456 --table my_user --hive-table hivetest --hive-import -m 1


     

    案例2在案例1的基础上,分别进行overwrite(覆盖)导入和into(直接加入)导入。  

           into: 命令同案例1   


      overwrite:

                  sqoop import --connect jdbc:mysql://hadoop-001:3306/test --username root --password 123456 --table test --hive-table hivetest --hive-import -m 1 --hive-overwrite


     

    案例3:在案例2的基础上,通过增加mysql的test表数据,增量导入到hive表中。


        sqoop import --connect jdbc:mysql://hadoop-001:3306/test --username root --password 123456 --table test --where "id>9" --hive-table hivetest --hive-import -m 1

           或者

           sqoop import --connect jdbc:mysql://hadoop-001:3306/test --username root --password 123456 --table test --query "select id,name from test where id>9" --hive-table hivetest --hive-import -m 1


     

    案例4:将test表中的数据导出到使用','分割字段的hive表(hivetest2)中。


        创建表: create table hivetest2(id int,name string) row format delimited fields terminated by ',';

           sqoop:

                  sqoop import --connect jdbc:mysql://hadoop-001:3306/test --username root --password 123456 --table test --hive-table hivetest2 --hive-import -m 1 --fields-terminated-by ","


     

    案例5将PARTITIONS表的数据导入到hdfs中。

        


       sqoop import --connect jdbc:mysql://hadoop-001:3306/metastore --username root --password 123456 --table  PARTITIONS --target-dir /wordcount -m 1


    可以看到hdfs有生成文件

    cat一下

    案例6在案例5的基础上,增量导入数据到hdfs中。

         


      sqoop import --connect jdbc:mysql://hadoop-001:3306/test --username root --password 123456 --table test --target-dir /test -m 1 --check-column id --incremental append --last-value 11


     

           2、export命令

    案例1:将hdfs上的文件导出到关系型数据库test2表中。

          


    ./sqoop export --connect jdbc:mysql://hadoop-001:3306/test --username root --password 123456 --table tb_dept --export-dir /test/dept.txt


     

    案例2将hive表(hivetest)数据导出到关系型数据库test2表中(使用insertOrUpdate方法导入)。

           hivetest表只留id为1,2,3,4,5的数据,其他数据删除。

           hivetest表分隔方式是'u0001',但是export命令默认使用','分隔数据

          


    sqoop export --connect jdbc:mysql://hadoop-001:3306/test --username root --password hive --table test2 --export-dir /hive/hivetest --input-fields-terminated-by "\01" --update-mode

    allowinsert --update-key id 


      3.其他命令

    list-databases命令


    sqoop list-databases --connect jdbc:mysql://hadoop-001:3306 --username root --password 123456


    list-tables


    sqoop list-tables --connect jdbc:mysql://hadoop-001:3306/default --username root --password 123456


    create-hive-table命令


    sqoop create-hive-table --connect jdbc:mysql://hadoop-001:3306/test --username root --password 123456--table test --hive-table hivetest


     help命令


    1. sqoop help
    2. sqoop help list-tables


     

  • 相关阅读:
    React中条件渲染
    React 中this.setStat是批量执行的, 它发现做三次是多余的,所以只执行一次
    React 修改获取state中的值
    POJ3417 Network (树上差分)
    POJ3349 Snowflake Snow Snowflakes(Hash)
    Codeforces Round #630 (Div. 2) C. K-Complete Word(字符串)
    Codeforces Round #630 (Div. 2) B. Composite Coloring(数论)
    Codeforces Round #630 (Div. 2) A. Exercising Walk(水题)
    Codeforces Round #629 (Div. 3)/1328 E.Tree Queries(LCA)
    洛谷P5836 [USACO19DEC]Milk Visits S(LCA/并查集)
  • 原文地址:https://www.cnblogs.com/Transkai/p/10556255.html
Copyright © 2011-2022 走看看