Fork me on GitHub

sqoop之旅2-基本使用

sqoop 基本使用

sqoop的主要功能是导入和导出

  • 导入
    • 读数据(row-by-row)
    • 并行化执行
    • 导入的结果可以是文本文件或者二进制序列化文件
  • 导出
    • 并行化读取HDFS文件

基本操作

sqoop实质上是一个工具箱,使用的时候需要指定哪个工具和控制工具的参数。

  1. 通过sqoop help,来查看sqoop支持哪些命令
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
$ sqoop help

Available commands:
codegen Generate code to interact with database records # 生成能够和数据库进行交互的代码
create-hive-table Import a table definition into Hive # 将生成的Hive表导入Hive中
eval Evaluate a SQL statement and display the results # 评估SQL语句,并且显示结果
export Export an HDFS directory to a database table # 将HDFS目录导出到数据库表中
help List available commands # 列出可用的命令
import Import a table from a database to HDFS # 将一个表从数据库--->HDFS中
import-all-tables Import tables from a database to HDFS # 将全部的表从数据表--->HDFS中
import-mainframe Import datasets from a mainframe server to HDFS # 从服务器中将数据库导入到HDFS
job Work with saved jobs # 工作与保存的任务
list-databases List available databases on a server # 列出可用的数据库
list-tables List available tables in a database # 列出数据库中的可用表
merge Merge results of incremental imports # 合并增量导入的数据
metastore Run a standalone Sqoop metastore # 运行一个独立的Sqoop元数据
version Display version information # 显示版本信息
  1. 查看某个命令的具体使用

查看import如何使用

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
(base) peter:sqoop-1.4.7 piqianchao$ sqoop help import

Common arguments:
--connect <jdbc-uri> Specify JDBC connect
string
--connection-manager <class-name> Specify connection manager
class name
--connection-param-file <properties-file> Specify connection
parameters file
--driver <class-name> Manually specify JDBC
driver class to use
--hadoop-home <hdir> Override
$HADOOP_MAPRED_HOME_ARG
--hadoop-mapred-home <dir> Override
$HADOOP_MAPRED_HOME_ARG
--help Print usage instructions
-P Read password from console
--password <password> Set authentication
password
--password-alias <password-alias> Credential provider
password alias
--password-file <password-file> Set authentication
password file path
--relaxed-isolation Use read-uncommitted
isolation for imports
--skip-dist-cache Skip copying jars to
distributed cache
--username <username> Set authentication
username
--verbose Print more information
while working

使用demo

  1. 直接使用参数传递
  2. 使用文件方式进行参数的传递:文件中允许空行和注释部分
1
2
3
4
5
 # 1. 直接使用
sqoop import \
--connect jdbc:mysql://localhost/db \
--username foo \
--table TEST \
1
2
3
4
5
6
7
8
9
10
11
# 2. 将参数写入文件中
sqoop --options-file /users/home/work/import.txt --table TEST

# 每行一个参数
# /users/home/work/import.txt
import
--connect

jdbc:mysql://localhost/db
--username
foo

本文标题:sqoop之旅2-基本使用

发布时间:2019年11月18日 - 23:11

原始链接:http://www.renpeter.cn/2019/11/18/sqoop%E4%B9%8B%E6%97%852-%E5%9F%BA%E6%9C%AC%E4%BD%BF%E7%94%A8.html

许可协议: 署名-非商业性使用-禁止演绎 4.0 国际 转载请保留原文链接及作者。

Coffee or Tea