Sqoop2 将hdfs中的数据导出到MySQL

本文详细介绍了Sqoop2的操作流程,包括进入终端、配置服务器、查看连接和配置信息,还阐述了创建HDFS和MySQL的Link、创建作业、查看作业以及启动作业等步骤,涉及数据库和HDFS的数据交互,为相关操作提供了具体指导。

1.进入sqoop2终端:

[root@master /]# sqoop2

2.为客户端配置服务器:

sqoop:000> set server --host master --port 12000 --webapp sqoop

 3.查看服务器配置:

sqoop:000> show version --all

4. 查看sqoop的所有连接:

sqoop 所有的连接固定为四个,如下:

sqoop:000> show connector

5.创建hdfs的link:

sqoop:000> create link --cid 3

sqoop:000> create link --cid 3
Creating link for connector with id 3
Please fill following values to create new link object
Name: hdfs_link

Link configuration

HDFS URI: hdfs://master:8020  // 这个地方一定要和hdfs中的地址对应
New link was successfully created with validation status OK and persistent id 2

5.创建MySQL的Link

sqoop:000> create link --cid 1
Creating link for connector with id 1
Please fill following values to create new link object
Name: mysql_link

Link configuration

JDBC Driver Class: com.mysql.jdbc.Driver
JDBC Connection String: jdbc:mysql://master:3306/app        
Username: root
Password: ****
JDBC Connection Properties: 
There are currently 0 values in the map:
entry# protocol=tcp
There are currently 1 values in the map:
protocol = tcp
entry# 
New link was successfully created with validation status OK and persistent id 3

6.查看当前的所有link

 sqoop:000> show link

7.创建job

sqoop:000> create job -f 1 -t 2
Creating job for links with from id 1 and to id 2
Please fill following values to create new job object
Name: hdfs_to_mysql

From Job configuration

Input directory: /yk/dl/GetAlarmHis/
Override null value: null 
Null value: null

To database configuration

Schema name: app
Table name: alarm_his
Table SQL statement: 
Table column names: 
Stage table name: 
Should clear stage table: 

Throttling resources

Extractors: 1
Loaders: 1
New job was successfully created with validation status OK  and persistent id 1

 

Name:一个标示符,自己指定即可。

Schema Name:指定Database或Schema的名字,在MySQL中,Schema同Database类似,具体什么区别没有深究过,但官网描述在创建时差不多。这里指定数据库名字为db_ez即可,本例的数据库。

Table Name:本例使用的数据库表为tb_forhadoop,自己指定导出的表。多表的情况请自行查看官方文档。

SQL Statement:填了schema name和table name就不可以填sql statement。sql语句中必须包含${CONDITIONS}字样,一般是where 1=1 and ${CONDITIONS}

Partition column: 在填写了sql statement的情况下,必须填写,用以对数据分区,一般为可唯一标识记录的数字型字段。

Partition column nullable:

Boundary query:

Last value:

后面需要配置数据目的地各项值:

Null alue:大概说的是如果有空值用什么覆盖

File format:指定在HDFS中的数据文件是什么文件格式,这里使用TEXT_FILE,即最简单的文本文件。

Compression codec:用于指定使用什么压缩算法进行导出数据文件压缩,我指定NONE,这个也可以使用自定义的压缩算法CUSTOM,用Java实现相应的接口。

Custom codec:这个就是指定的custom压缩算法,本例选择NONE,所以直接回车过去。

Output directory:指定存储在HDFS文件系统中的路径,这里必须指定一个存在的路径,或者存在但路劲下是空的,貌似这样才能成功。

Append mode:用于指定是否是在已存在导出文件的情况下将新数据追加到数据文件中。

Extractors:大概是etl执行次数,比如填2,那么hdfs的输出中数据将会重复2次…依次类推

Loaders:决定了最后执行的reduce数量(可见下面的源码MapreduceSubmissionEngine.submit方法)

8.查看job

sqoop:000> show job

9.启动job

 

sqoop:001> show link       显示所有链接

sqoop:001> create link --cid 1    创建连接

sqoop:000> delete link --lid 1     删除link
sqoop:001> show job       显示所有job

sqoop:001> create job --f 2 --t 1   创建job ( 从link 2 向link 1导入数据)
sqoop:000> start job --jid 1      启动job
sqoop:000> status job --jid 1      查看导入状态

sqoop:000> delete job --jid 1      删除job

 

在sqoop客户端设置查看job详情:

set option --name verbose --value true

 

https://blog.youkuaiyun.com/wdr2003/article/details/80964588

教程:https://www.2cto.com/database/201411/356011.html

转载于:https://www.cnblogs.com/chuijingjing/p/10728749.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值