Sqoop2 將hdfs中的數據導出到MySQL


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.csdn.net/wdr2003/article/details/80964588

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


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM