大数据之Hive:DML数据操作(三)

数据导出
1.Insert导出
1-1.将查询的结果导出到本地

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

1-2.将查询的结果格式化导出到本地

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

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

hive (default)> insert overwrite directory '/user/hadoop/student2'
             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)

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

4.Export导出到HDFS上

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

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

2.清除表中数据(Truncate)
注意:Truncate只能删除管理表,不能删除外部表中数据

hive (default)> truncate table student;

猜你喜欢

转载自blog.csdn.net/weixin_43597208/article/details/112555552
今日推荐