Hive的DML-数据导出

1、Insert导出

将查询的结果导出到本地

hive (default)> insert overwrite local directory '/opt/module/datas/export/student'
select * from student;

将查询的结果格式化导出到本地

hive(default)>insert overwrite local directory '/opt/module/datas/export/student1'
        ROW FORMAT DELIMITED FIELDS TERMINATED BY '\t' 
        select * from student;

将查询的结果导出到HDFS上(没有local)

hive (default)> insert overwrite directory '/user/afei/student'
      ROW FORMAT DELIMITED FIELDS TERMINATED BY '\t' 
      select * from student;

2、Hadoop命令导出到本地

hive (default)> dfs -get /user/hive/warehouse/student/month=201709/000000_0
/opt/module/datas/export/student3.txt;

3、Hive Shell 命令导出

本语法:(hive -f/-e 执行语句或者脚本 > file)

[afei@hadoop102 hive] bin/hive -e 'select * from default.student;' >
 /opt/module/datas/export/student4.txt;

4、Export导出到HDFS

hive (default)> export table default.student to
 '/user/hive/warehouse/export/student';

export和import主要用于两个Hadoop平台集群之间Hive表迁移。

5、清除表中数据(Truncate)

注意:Truncate只能删除管理表,不能删除外部表中数据

hive (default)> truncate table student;

 

猜你喜欢

转载自blog.csdn.net/QJQJLOVE/article/details/106996681