1.文法
hive> load data [local] inpath '/opt/module/datas/student.txt' overwrite | into table student [partition (partcol1=val1,…)];
(1)load data:表示加載資料
(2)local:表示從本地加載資料到hive表;否則從HDFS加載資料到hive表
(3)inpath:表示加載資料的路徑
(4)overwrite:表示覆寫表中已有資料,否則表示追加
(5)into table:表示加載到哪張表
(6)student:表示具體的表
(7)partition:表示上傳到指定分區
load data local inpath '/opt/module/datas/student.txt' into table default.student;
2.導出
1 Insert導出
1.将查詢的結果導出到本地
hive (default)> insert overwrite local directory '/opt/module/datas/export/student'
select * from student;
2.将查詢的結果格式化導出到本地
hive(default)>insert overwrite local directory '/opt/module/datas/export/student1'
ROW FORMAT DELIMITED FIELDS TERMINATED BY '\t' select * from student;
3.将查詢的結果導出到HDFS上(沒有local)
hive (default)> insert overwrite directory '/user/atguigu/student2'
ROW FORMAT DELIMITED FIELDS TERMINATED BY '\t'
select * from student;
2 Hadoop指令導出到本地
hive (default)> dfs -get /user/hive/warehouse/student/month=201709/000000_0
/opt/module/datas/export/student3.txt;
3 Hive Shell 指令導出
基本文法:(hive -f/-e 執行語句或者腳本 > file)
[atguigu@hadoop102 hive]$ bin/hive -e 'select * from default.student;' >
/opt/module/datas/export/student4.txt;