1:insert 导出
语法
INSERT OVERWRITE [LOCAL] DIRECTORY directory1
[ROW FORMAT row_format] [STORED AS file_format] (Note: Only available starting with Hive 0.11.0)
SELECT ... FROM ...
将查询的结果导出到本地
insert overwrite local directory '/install/hivedatas/stu' select * from stu;
将查询的结果格式化导出到本地
insert overwrite local directory '/install/hivedatas/stu2' row format delimited fields terminated by ',' select * from stu;
将查询的结果导出到HDFS上 (没有local)
insert overwrite directory '/hivedatas/stu' row format delimited fields terminated by ',' select * from stu;
2:Hive Shell 命令导出
基本语法
hive -e "sql语句" > file
hive -f sql文件 > file
在linux命令行中,运行如下命令;
导出myhive.stu表的数据到本地磁盘文件/install/hivedatas/student1.txt
hive -e 'select * from myhive.stu;' > /install/hivedatas/student1.txt
3:export导出到HDFS上
export table myhive.stu to '/install/hivedatas/stuexport';