一,hive导入数据方式
- load数据方式
1.1 从本地磁盘导入:
load data local inpath ‘/localpath’ into table table1; #最加的方式
load data local inpath ‘/opt/mydata.csv’ overwrite into table table1; #覆写的方式
1.2 从HDFS导入(无关键字local):
load data inpath ‘/localpath’ into table table1; #最加的方式
load data inpath ‘/localpath’ overwrite into table table1; #覆写的方式
- 表操作方式
2.1 insert into … select
insert into table1 select id,name from table1; #最加的方式
insert overwrite into table1 select id,name from table1; #覆写的方式
2.1 create … as select
create table1 as select * from table2 where 1=1;
-
import导入方式
import table student2 from ‘/user/hive/warehouse/export/student’;
#注意:import只能导入export命令从Hive到出去的数据,且目标表可以为空,如果已经创建则必须是空表 -
建hive外表的方式location导入数据(注意建表时分隔符)
create external table if not exists student5( id int, name string) row format delimited fields terminated by ‘\t’ location '/student; -
sqoop导入(略)
具体查看sqoop导入方式;
二,hive导出数据方式
1,insert导出方式
导出到本地文件:
insert overwrite local directory ‘/opt/module/hive/data/export/student’
ROW FORMAT DELIMITED FIELDS TERMINATED BY ‘\t’ #指定分隔符为空格
select * from student;
导出到HDFS文件系统(无local关键字):
insert overwrite directory ‘/opt/module/hive/data/export/student’
ROW FORMAT DELIMITED FIELDS TERMINATED BY ‘\t’
select * from student;
2,dfs导出方式(注意hive建表必须时textfile格式)
#类似于hdfs导出方式
dfs -get /tmp/student.txt /tmp/student.txt;
3,export
export 和 import 主要用于两个 Hadoop 平台集群之间 Hive 表迁移。
export table ds.table1 to ‘/tmp/export/table1’;
4,hive shell(hive -e/-f)
hive shell执行sql语句,结果存储到文件
bin/hive -e ‘select * from ds.table1;’ > /tmp/export/table1.txt;
hive shell执行sql文件,结果存储到文件
bin/hive -f hivesql1.sql > /tmp/export/table1.txt;
5,sqoop导出(略)
具体查看sqoop导出方式;