前言:如何导出Hive中的数据,我接触到的有五种方式。接下来以student表为例进行介绍:

hive导出json格式 hive导出数据的几种方式_hive

1. Insert导出

1.1 导出数据到本地

insert overwrite local directory '/opt/bigdatacase/export_dir/student' select id,name from student;

hive导出json格式 hive导出数据的几种方式_hive_02


可是各个字段之间的数据都连在一起了,所以我们应该格式化导出的数据。

1.2 格式化导出数据到本地

insert overwrite local directory '/opt/bigdatacase/export_dir/student' 
row format delimited fields terminated by '\t'
select id,name from student;

hive导出json格式 hive导出数据的几种方式_hive导出json格式_03

1.3 导出数据到HDFS

insert overwrite directory '/user/'
row format delimited fields terminated by '\t'
select id,name from student;

hive导出json格式 hive导出数据的几种方式_hive_04

2. Hadoop命令导出到本地

找到对应文件,执行命令:

dfs -get /user/hive/warehouse/test0817.db/student/student.txt /opt/bigdatacase/export_dir/stduent.txt;

hive导出json格式 hive导出数据的几种方式_导出数据_05


hive导出json格式 hive导出数据的几种方式_hive_06

3. Hive Shell命令导出

扩展:也可以执行sql脚本 hive -f sql脚本 > file 注意:这条命令是shell命令,不是在Hive客户端里面执行的

hive -e 'select * from test0817.student' > /opt/bigdatacase/export_dir/student.txt

hive导出json格式 hive导出数据的几种方式_hive导出json格式_07

4. Export导出到HDFS上

export table student to '/user/student';

hive导出json格式 hive导出数据的几种方式_导出数据_08

5. Sqoop导出

这个借助到Sqoop,后续更新。