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. 继承映射中的java.lang.IllegalArgumentException: org.hibernate.hql.internal.ast.QuerySyntaxException: person is not mapped [FROM person]

    继承映射中查询对象的过程中报错: java.lang.IllegalArgumentException: org.hibernate.hql.internal.ast.QuerySyntaxExcep ...

  2. 分析无线遥控器信号并制作Hack硬件进行攻击

    无线遥控器(无线电遥控器)在我们生活中非常常见,应用于各种场景,方便着用户的使用.不过大多数还是用于安防方面的,比如: 遥控报警器.电动卷帘门.电动伸缩门.遥控电开关.无线遥控门铃…… 1.无线遥控器 ...

  3. Pycharm连接Git及使用

    环境: Git-2.7.2-32-bit_setup.1457942412.exe TortoiseGit-2.4.0.2-64bit.msi 安装配置Git后,打开Pycharm.file--> ...

  4. java学习笔记19(Arrays类)

    Arrays类: 此类包含用来操作数组的各种方法(比如升序和搜索): import java.util.Arrays; public class Demo { public static void m ...

  5. LeetCode--1、26、27、35、53 Array(Easy)

      1. Two Sum Given an array of integers, return indices of the two numbers such that they add up to ...

  6. POJ 1287 Networking(最小生成树裸题有重边)

    Description You are assigned to design network connections between certain points in a wide area. Yo ...

  7. Nginx 浏览器打开是下载状态

    location ~ \.php(.*)$ { fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_split_path_inf ...

  8. webgl opengl教程样例

    webgl2样例: http://webglsamples.org opengl教程: https://learnopengl.com/ http://www.opengl-tutorial.org/ ...

  9. Django之模板层-自定义过滤器以及标签

    自定义标签与过滤器 在settings中的INSTALLED_APPS配置当前app,不然django无法找到自定义的simple_tag. 在app中创建templatetags模块(模块名只能是t ...

  10. AI之路,第一篇:python数学知识1

    python 数学知识1 1,向量: 一个向量是一列数.这些数是有序排列的:通过次序中的索引,可以确定每个单独的数: 2, 矩阵: 由m x n 个数aij(i=1,2,3,…, m;  j=1,2, ...