????? 把數據裝載到hive庫一般有兩種,一種是通過etl抽取數據然后裝載數據到hive,一種是文件裝載到hive庫,導出hive庫也有兩種方式,一種是直接裝載到傳統庫,一種是生成文件之后再裝載到傳統庫,如下所示:
文件導入導出:
1. 從本地文件系統裝載到hive表
load data local inpath 'aaa.txt' into table hive_test_table partition(op_time=20170212,op_hour=2017021222);
或者:
put aaa.txt /hive_test_table/op_time=20170212/op_hour=2017021222;
2.hdfs文件導入到hive表
load data inpath '/hive_test_table/op_time=20170212/op_hour=2017021222/aaa.txt' into table hive_test_table;
3.從hive庫導出文件到本地文件系統
insert?overwrite?local?directory?'/data8/demo'?row?format?delimited?fields?terminated?by?'^'??select?*?from?test_hive_table where?op_month= 201701 and?op_time= 20170111 and?op_hour= 2017011111 ;
sqoop數據導入導出:
1.mysql數據庫數據導入hive庫
sqoop import --connect jdbc:mysql://ip:端口/sqoop --username 用戶名 --password 密碼--table mysql表 -m 1
2.hive數據導入到mysql數據庫
sqoop export --connect jdbc:mysql://ip:端口/sqoop --username 用戶名 --password 密碼--table mysql表 --export-dir hdfs:/user/warehouse/students/00000_00
3.oracle數據導入hive庫
sqoop import --hive-import --connect jdbc:oracle:thin:@ip:端口:數據庫 --username 用戶名 --password 密碼 --verbose -m 1 --table 表名
注:并發數設置為1
hive庫表與表之間的導入:
insert into hive_test_table partition(op_time=20170212,op_hour=2017021222) select * from hive_test_table_1;