Hive和MySQL資料互導

2021-09-19 01:21:55 字數 3864 閱讀 6261

用sqoop進行hive和mysql之間的資料互導

use anticheat;

create table anticheat_blacklist(

userid varchar(30) primary key ,

dt int,

update_time timestamp,

delete_flag int,

operator varchar(30)

);

用sqoop export全量匯出hive表資料入mysql,具體命令如下:

sqoop export -d mapred.job.queue.name=datacenter 

--connect jdbc:mysql://localhost:3306/anticheat?tinyint1isbit=false

--username root

--password ^qn9dfypm

--table anticheat_blacklist

--input-fields-terminated-by '\t'

--input-null-string '\\n'

--input-null-non-string '\\n'

--export-dir hdfs://dc5/user/test/hive/online/anticheat_blacklist_mysql

sqoop export -d mapred.job.queue.name=datacenter 

--connect jdbc:mysql://localhost:3306/anticheat?tinyint1isbit=false

--username root

--password ^qn9dfypm

--table anticheat_blacklist2

--input-fields-terminated-by '\t'

--input-null-string '\\n'

--input-null-non-string '\\n'

--update-key update_time

--update-mode allowinsert

--export-dir hdfs://dc5/user/test/hive/online/anticheat_blacklist_mysql2

建立同步mysql表的hive表

create table test.anticheat_blacklist_mysql(

key string,

dt int,

update_time timestamp,

delete_flag int,

operator string

) row format delimited fields terminated by '\t'

stored as textfile

location 'hdfs://dc5/user/test/hive/online/anticheat_blacklist_mysql';

用sqoop import全量匯出mysql表資料入hive表,具體命令如下:

sqoop import -d mapred.job.queue.name=datacenter 

--connect jdbc:mysql://localhost:3306/anticheat?tinyint1isbit=false

--username root

--password ^qn9dfypm

--table anticheat_blacklist

--delete-target-dir

--beeline "jdbc:hive2:"

--hive-import --fields-terminated-by '\t'

--hive-database test

--hive-table anticheat_blacklist_mysql

--null-string '\\n'

--null-non-string '\\n'

--hive-overwrite

--outdir /home/test/data/anticheat/mysql2hive

null字串轉為null,新增下面兩條引數可以實現:

增量匯入:(根據時間來匯入,如果表中沒有時間屬性,可以增加一列時間簇)

核心引數:

注意:上面三個引數都必須新增

執行語句:

sqoop import -d mapred.job.queue.name=datacenter 

--connect jdbc:mysql://localhost:3306/anticheat?tinyint1isbit=false

--username root

--password ^qn9dfypm

--table anticheat_blacklist

--delete-target-dir

--hive-import --fields-terminated-by '\t'

--beeline "jdbc:hive2:"

--hive-database test

--hive-table anticheat_blacklist_mysql

--null-string '\\n'

--hive-overwrite

--check-column update_time

--incremental lastmodified

--last-value "2019-04-12 14:31:34"

--outdir /home/test/data/anticheat/mysql2hive

以上語句使用 lastmodified 模式進行增量匯入,結果報錯:

錯誤資訊:--incremental lastmodified option for hive imports is not supported. please remove the parameter --incremental lastmodified

錯誤原因:sqoop 不支援 mysql轉hive時使用 lastmodified 模式進行增量匯入,但mysql轉hdfs時可以支援該方式!

sqoop import -d mapred.job.queue.name=datacenter 

--connect jdbc:mysql://localhost:3306/anticheat?tinyint1isbit=false

--username root

--password ^qn9dfypm

--table anticheat_blacklist

--delete-target-dir

--hive-import --fields-terminated-by '\t'

--hive-database test

--hive-table anticheat_blacklist_mysql

--null-string '\\n'

--null-non-string '\\n'

--check-column update_time

--last-value "2019-04-12 14:31:34"

--outdir /home/test/data/anticheat/mysql2hive

增量匯入成功!

sql access excel 資料互導

一 sql server 和access的資料匯入匯出 常規的資料匯入匯出 使用dts嚮導遷移你的access資料到sql server,你可以使用這些步驟 1在sql server企業管理器中的tools 工具 選單上,選擇data transformation 2services 資料轉換服務 ...

資料庫互導

1 sqlserver與access互導 方法一 用sql語句 匯出到access insert into openrowset microsoft.jet.oledb.4.0 x a.mdb admin a表 select from 資料庫名.b表 匯入access insert into b表 ...

hive庫之間檔案的互導

找到所要匯出的檔案,get下來,並scp到同網段的其它主機節點下,就是receive方的機器上,路徑自定義即可。scp root test mg02 opt hive data hive中建立相同的元資料資訊 表結構 檢視send方的建表語句,用於在receive方建表 show create ta...