簡單使用Sqoop的命令

2021-09-19 03:46:29 字數 1944 閱讀 3613

一、import命令

1.將mysql表test中的資料匯入hive的hivetest表,hive的hivetest表不存在

sqoop import --connect jdbc:mysql: --username hive

--password hive --table test --hive-table hivetest --hive-import -m 1

2.在1的基礎上,分別進行overwrite匯入和into(直接加入)匯入

into:命令同1

overwrite:

sqoop import --connect jdbc:mysql: --username hive

--password hive --table test --hive-table hivetest --hive-import -m 1 --hive-overwrite

3.在2的基礎上,通過增加mysql的test表資料,增量匯入到hive表中

sqoop import --connect jdbc:mysql: --username hive

--password hive --table test --where "id>3" --hive-table hivetest --hive-import -m 1

或者 sqoop import --connect jdbc:mysql: --username hive

--password hive --table test --query "select id,name from test where id>3" --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: --username hive --password hive --table test

--hive-table hivetest2 --hive-import -m 1 --fields-terminated-by ","

5.將test表中資料匯入到hdfs中。

sqoop import --connect jdbc:mysql: --username hive --password hive --table test

--target-dir /test -m 1

6.在5的基礎上,增量匯出資料到hdfs中

sqoop import --connect jdbc:mysql: --username hive --password hive

二、export命令

1.將hdfs上的檔案匯出到關係型資料庫test2表中

sqoop export --connect jdbc:mysql: --username hive --password hive

--table test2 --export-dir /test

2.將hive表(hivetest)資料匯出到關係型資料庫test2表中(使用insertorupdate方法匯入)

hivetest表分割方式是'\u0001',但是export命令預設使用','分割資料

sqoop export --connect jdbc:mysql: --username hive --password hive

--table test2 --export-dir /hive/hivetest --input-fields-terminated-by "\\01" --update-mode

allowinsert --update-key id

Sqoop (二)Sqoop 的簡單使用案例

二 匯出資料 三 指令碼打包 在sqoop中,匯入 概念指 從非大資料集群 rdbms 向大資料集群 hdfs,hive,hbase 中傳輸資料,叫做 匯入,即使用import關鍵字。確定mysql服務開啟正常 在mysql中新建一張表並插入一些資料 mysql uroot p000000 mysq...

Sqoop 的簡單使用案例

1 匯入資料 在 sqoop 中,匯入 概念指 從非大資料集群 rdbms 向大資料集群 hdfs,hive,hbase 中傳輸資料,叫做 匯入,即使用 import 關鍵字。1 rdbms 到 hdfs 1 確定 mysql 服務開啟正常 2 在 mysql 中新建一張表並插入一些資料 mysql...

Sqoop的簡單使用案例

rdbms到hive rdbms到hbase hive hdfs到rdbms 指令碼打包 1.確定mysql服務開啟正常 2.在mysql中新建一張表並插入一些資料 mysql uroot proot mysql create database company mysql create table ...