解決sqoop匯入關係庫更新聯合主鍵的問題

2021-07-04 10:04:22 字數 1316 閱讀 5041

[author]: kwu 

解決sqoop匯入關係庫更新聯合主鍵的問題,把資料從hive中匯入關係庫,如果關係庫表有聯合主鍵的情況,且需要把新匯入的資料更新原來的資料。

以下提供參考的示例:

1、建立關係庫表

create table

test123

(id int not null,

name varchar(25) not null,

age int,

primary key (id, name)

)engine=myisam default charset=utf8

2、建立hive表

drop table default.test123;

create table default.test123

( id int,

name string,

age int

)row format delimited fields terminated by '\t'

stored as textfile;

匯入測試資料:

insert overwrite table default.test123 select 1,'bill',5 from default.kwu_test limit 1;

3、sqoop匯入mysql資料庫

sqoop export  --connect jdbc:mysql: --update-key "id,name" --update-mode allowinsert  --username kwu  --password '123456'  --table test123  --fields-terminated-by '\t' --columns "id,name,age" --export-dir /hive/warehouse/test123

說明: 

1)  -update-key 指定聯合主鍵的值

2)  --update-mode allowinsert 指定更新的模式為可插入,預設為 updateonly

修改測試資料:

insert overwrite table default.test123 select 1,'bill',6 from default.kwu_test limit 1;

檢視mysql資料庫中age已經修改為6.

解決sqoop匯入關係庫更新聯合主鍵的問題

解決sqoop匯入關係庫更新聯合主鍵的問題,把資料從hive中匯入關係庫,如果關係庫表有聯合主鍵的情況,且需要把新匯入的資料更新原來的資料。以下提供參考的示例 1 建立關係庫表 sql view plain copy create table test123 id int notnull name ...

解決sqoop匯入關係庫更新聯合主鍵的問題

author kwu 解決sqoop匯入關係庫更新聯合主鍵的問題,把資料從hive中匯入關係庫,如果關係庫表有聯合主鍵的情況,且需要把新匯入的資料更新原來的資料。以下提供參考的示例 1 建立關係庫表 sql view plain copy create table test123 id int no...

sqoop更新匯入總結,從hive到mysql

首先語句上很簡單,sqoop export connect jdbc mysql username cxk password jinitaimei table test table columns a,b,c,d,e hcatalog database hive database01 hcatalo...