导入数据:
1.将hive运行所在机器的本地磁盘的文件导入表中
load data local inpath '/root/web.log.1' into [overwrite] table t_1;
into的意思是追加,overwrite的意思是覆盖。
在hive的表中没有主键这个概念。
2.将hdfs中的文件导入表中
load data inpath '/user.data.2' into table t_1;
不加local关键字,则是从hdfs的路径中移动文件到表目录中。
3.从别的表查询数据后插入到一张指定的表中。
create table t_day01
as
select ip,url from t_day;
4.从别的表查询数据后插入到一张已存在的表中
假如已存在一张表,可以先建好:create table t_day02 like t_day01
可以使用desc查看表目录。
然后从t_day中查询出一些数据出来插入到t_day02中。
insert into table t_dat02
select * from t_day01 where staylong=300;
导出数据:
1.将查询出的数据导出到hdfs目录:
insert overwrite directory '/a'
select * from t_day02;
2.将hive中的数据导出到本地:
insert overwrite local directory '/a'
select * from t_day02;
3.既然导出到hdfs目录了,我么就可以尝试建立一个外部表
这里我们要注意hive的默认分隔符是ctrl+a ------>\001
create external table t_day03(ip string,url string)
row format delimited
fields terminated by '\001'
location '/a/';