1.向表中装载数据(Load)
local:表示从本地加载数据到hive表;或从HDFS加载数据到hive表
load data [local] inpath '/opt/module/datas/student.txt' [overwrite] into table student [partition (partcol1=val1,…)];
#hdfs [overwrite]表示是否覆盖,不覆盖则追加啊
load data inpath '/data/student.txt' [overwrite] into table stu_par partition(class='03');
#本地
load data [local] inpath '/opt/module/dates/student.txt' into table stu_par partition(class='01');
(1)load data:表示加载数据
(2)local:表示从本地加载数据到hive表;否则从HDFS加载数据到hive表
(3)inpath:表示加载数据的路径
(4)overwrite:表示覆盖表中已有数据,否则表示追加
(5)into table:表示加载到哪张表
(6)student:表示具体的表
(7)partition:表示上传到指定分区
#先在hdfs://hadoop102:8020/xxx文件夹上传一份student.txt
#hdfs的导入是移动,而移动导入是复制
load data inpath '/xxx/student.txt' overwrite into table student;
2.通过查询语句向表中插入数据(Insert)
insert into:以追加数据的方式插入到表或分区,原有数据不会删除
insert overwrite:会覆盖表或分区中已存在的数据
注意:insert不支持插入部分字段
truncate table student;
清空表
insert into table student select id,name from stu_par where class="01";
3.查询语句中创建表并加载数据(As Select)
根据查询结果创建表(查询的结果会添加到新创建的表中)
create table stu_result as select * from stu_par where id=1001;
4.创建表时通过Location指定加载数据路径
#先在hdfs://hadoop102:8020/xxx文件夹上传一份student.txt
create external table student2
(id int ,name string)
row format delimited fields terminated by '\t'
location '/xxx';
1.Insert导出
insert overwrite local directory '/opt/module/datas/export/student'
select * from student;
2.Insert带格式导出
insert overwrite local directory '/opt/module/datas/export/student1'
ROW FORMAT DELIMITED FIELDS TERMINATED BY '\t' select * from student;
3.Hadoop命令导出到本地
dfs -get /user/hive/warehouse/student/month=201709/000000_0
/opt/module/datas/export/student3.txt;
4.bash命令行导出
hive -e 'select * from default.student;' >
/opt/module/datas/export/student4.txt;
5.整张表Export导出到HDFS上
export table student to '/export/student';
6.从导出结果导入到Hive
import table student3 from '/export/student';
1.truncate 只删表数据不删表本身体
truncate table student;