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


Sqoop 导入及导出表数据子集命令详解的更多相关文章

  1. mysql导入导出命令详解

    mysql导入导出命令详解 该命令适用于临时备份操作. 一.导出数据库用mysqldump命令(注意mysql的安装路径,即此命令的路径): /usr/local/mysql/bin/  ---> ...

  2. Android Studio系列教程五--Gradle命令详解与导入第三方包

    Android Studio系列教程五--Gradle命令详解与导入第三方包 2015 年 01 月 05 日 DevTools 本文为个人原创,欢迎转载,但请务必在明显位置注明出处!http://s ...

  3. oracle中imp命令详解 .

    转自http://www.cnblogs.com/songdavid/articles/2435439.html oracle中imp命令详解 Oracle的导入实用程序(Import utility ...

  4. 用数据泵技术实现逻辑备份Oracle 11g R2 数据泵技术详解(expdp impdp)

    用数据泵技术实现逻辑备份 from:https://blog.csdn.net/weixin_41078837/article/details/80618916 逻辑备份概述 逻辑备份时创建数据库对象 ...

  5. Docker命令详解

    Docker命令详解   最近学习Docker,将docker所有命令实验了一番,特整理如下: # docker --help Usage: docker [OPTIONS] COMMAND [arg ...

  6. vmstat 命令详解 转载

    vmstat 命令详解   procs:r-->在运行队列中等待的进程数b-->在等待io的进程数w-->可以进入运行队列但被替换的进程 memoyswap-->现时可用的交换 ...

  7. Git命令详解

    一个中文git手册:http://progit.org/book/zh/ 原文:http://blog.csdn.net/sunboy_2050/article/details/7529841 前面两 ...

  8. db2常用命令(详解)大全

    近一年来在项目开发中使用到了IBM的DB2 9.1的数据库产品,跟Oracle相比一些命令有很大的区别,而它最大的功能是支持      xml存储.检索机制,通过XPath进行解析操作,使开发人员免于 ...

  9. net user命令详解

    net use \\ip\ipc$ " " /user:" " 建立IPC空链接 net use \\ip\ipc$ "密码" /user: ...

随机推荐

  1. 在Intellij IDEA中修改模板中user变量名称

    在Intellij IDEA中的注释模板中的${user}名称是根据当前操作系统的登录名来取的,有时候登录名称和我们实际的user名称并不相同. 修改方法如下: 方法一:可以在settings的fil ...

  2. getHibernateTemplate().save(t)执行不成功,数据不能插入到数据库

    BaseDaoImpl类中的代码如下 public void save(T t) {System.out.println(666);getHibernateTemplate().save(t);    ...

  3. Arrays.copyOfRange()

    Comparable[] aux = Arrays.copyOfRange(arr,from, to); 复制数组arr, from下标开始, to下标结束. 但是不包括to. 所以复制代码为 Com ...

  4. angularJS使用编写KindEditor,UEidtor,jQuery指令,双重绑定

    第一步 <!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8 ...

  5. [转]Poisson Distribution

    Poisson Distribution Given a Poisson process, the probability of obtaining exactly successes in tria ...

  6. python 中的堆 (heapq 模块)应用:Merge K Sorted Lists

    堆是计算机科学中一类特殊的数据结构的统称.堆通常是一个可以被看做一棵树的数组对象.在队列中,调度程序反复提取队列中第一个作业并运行,因为实际情况中某些时间较短的任务将等待很长时间才能结束,或者某些不短 ...

  7. 一些Go操作Kafka的问题

    1)包的选择 confluent-kafka-go使用了rdkafka的c库,破坏了go代码的收敛,不使用: sarama不支持groud id 的功能,写consumer需要自己管理消费的parti ...

  8. scrapt中的数据提取,采用js2xml库

    这个一个爬去美团的例子,应为数据都是在script中,小心封ip,尽量少运行. 先导入库几个库 import requests from bs4 import BeautifulSoup from l ...

  9. leetcode 772.Basic Calculator III

    这道题就可以结合Basic Calculator中的两种做法了,分别是括号运算和四则运算的,则使用stack作为保持的结果,而使用递归来处理括号内的值的. class Solution { publi ...

  10. Gym101002 2016NAIPC(队内第7次训练)

    (由于先看的最后一题,然后又一直WA,导致这场有点爆炸,我背锅. A .Fancy Antiques 题意: 选择最多k个商店,买n个物品,每个物品分别对应两个店售卖,求最小花费是多少.n<10 ...