sqoop適用的資料來源 sqoop資料遷移工具

2021-10-18 17:30:35 字數 2949 閱讀 7129

sqoop:hdfs 資料庫 資料遷移工具

(注:**為了表達清晰做了換行,執行時請放在一行中,使用空格隔開,或者加』\』進行行連線)

一.安裝:安裝在一台節點上

1.上傳sqoop

2.安裝和配置

在profiles中新增sqoop到環境變數

將資料庫連線驅動拷貝到$sqoop_home/lib裡

二.使用

第一類:資料庫中的資料匯入到hdfs上

指定列 –columns

./sqoop import

--connect jdbc:mysql:

--username root

--password 123

--table trade_detail

--columns 'id, account, income, expenses'

如果不指定列,則預設匯出所有的列,**例如:

./sqoop import

--connect jdbc:mysql:

--username root

--password 123

--table orders

指定輸出路徑 –target-dir、指定資料分隔符–fields-terminated-by(如果不指定,預設為」 , 「)

./sqoop import

--connect jdbc:mysql:

--username root

--password 123

--table tablename

--target-dir '/sqoop/td'(hdfs的目錄)

--fields-terminated-by '\t'

./sqoop import

--connect jdbc:mysql:

--username root

--password 123

--table orders

--target-dir /sqoop

指定map數量 -m

./sqoop import

--connect jdbc:mysql:

--username root

--password 123

--table trade_detail

--target-dir '/sqoop/td1'

--fields-terminated-by '\t'

-m 2

增加where條件 –where, 注意:條件必須用引號』 『引起來

./sqoop import

--connect jdbc:mysql:

--username root

--password 123

--table trade_detail

--where 'id>3'

--target-dir '/sqoop/td2'

增加query語句(語句預設寫一行裡面,使用『 \ 』將語句換行)

./sqoop import

--connect jdbc:mysql:

--username root

--password 123 \

--query 'select * from trade_detail where id > 2 and $conditions'

--split-by trade_detail.id

--target-dir '/sqoop/td3'

./sqoop import

--connect jdbc:mysql:

--username root

--password 123

--query 'select * from orders where id < 5 and $conditions'

-m 1

--target-dir /sqoop/td4 (字元轉義有錯 在記事本裡敲一遍再執行)

注意:如果使用–query這個命令的時候,需要注意的是where後面的引數,and $conditions這個引數必須加上

而且存在單引號與雙引號的區別,如果–query後面使用的是雙引號,那麼需要在$conditions前加上 \ 轉義 即 \$conditions

./sqoop import

--connect jdbc:mysql:

--username root

--password 123

--query 'select * from orders where id < 5 and $conditions' -m 1

--target-dir /sqoop/td4

--split-by user_id

第二類:將hdfs上的資料匯出到資料庫中( 不要忘記指定分隔符(預設是「,」))

./sqoop export

--connect jdbc:mysql:

--username root

--password 123

--export-dir '/td3'

--table td_bak -m 1

--fields-terminated-by ','

注意:匯出資料時,要清楚源資料的列分隔符是什麼,並且要求如果不是預設的分隔符,一定要指定出來

指定分隔符 –fields-terminated-by

--fields-terminated-by ','

以逗號作為分隔符

4.配置mysql遠端連線

grant all privileges on itcast.* to 'root'@'192.168.1.201' identified by '123' with grant option;

flush privileges;

grant all privileges on *.* to 'root'@'%' identified by '123' with grant option;

flush privileges

WPF 的 資料來源屬性 和 資料來源

一 資料來源 資料物件 屬性 path 或 path的值 path vm.property或m.property 通常具有通知功能 特例除外 二 path不能孤立而存在,它一定具有所歸屬的資料來源,一定要找到path 確切的說 是它的值 所歸屬的資料來源,說明如下 資料來源 資料物件 1 指定控制項...

SpringBoot學習 資料來源(一)單資料來源

springboot2.1.9預設支援三種資料來源 connection pool com.zaxxer.hikari.hikaridatasource org.apache.tomcat.jdbc.pool.datasource org.apache.commons.dbcp2.basicdata...

LINQ To Objects 的資料來源

linq to objects的資料來源 文 黃忠成 在 linq to objects 的架構中,只要實作了 ienumerable 介面的物件,皆可做為 linq to objects 的資料來源,那具體有那些呢?見下表。型別 說明 ienumerable 系列 1 具型陣列,如 string ...