load data local inpath '/root/hivedata/stu.txt'
[overwrite] into table student [partition(partcoll=vall,……)];
load data:表示加载数据
local:表示从本地加载数据到hive表,否则从HDFS加载数据到hive表
inpath:表示加载数据的路径
overwrite:表示覆盖表中已有数据
into :表示加载到哪张表,表示追加
student:表示具体的表
partition:表示上传到指定分区
2、实操过程
0.1创建一张表
create table student(id string,name string)
row format delimited fields terminated by '\t';
0.2加载本地文件到hive
load data local inpath '/root/hivedata/student.txt' into table default.student; === 这个加载是cp复制
0.3上传文件到HDFS
hdfs dfs -put /root/hivedata/student.txt /datas/;
0.4加载HDFS上的数据到hive
load data inpath '/datas/student.txt' into table default.student; === 这个加载是移动
二.通过查询语句向表中插入数据(Insert)
1、创建一张分区表
create table student(id int,name string) partitioned by (month string)
row format delimited fields terminated by '\t';
2、原始插入数据
insert into table student partition(month='202001') values(1,'haohao');
3、基本模式插入
insert overwrite table student partition (month='202001') select id,name from student where month='202002')