将hive表中的数据导出到其他任意目录,例如linux本地磁盘,例如hdfs,例如mysql等等

一、insert导出

将查询的结果导出到本地
insert overwrite local directory '/export/servers/exporthive/a' select * from score;

将查询的结果格式化导出到本地
insert overwrite local directory '/export/servers/exporthive' row format delimited fields terminated by '\t' collection items terminated by '#' select * from student;

collection items terminated by '#'   对集合类型使用#来进行分割

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

insert overwrite directory '/export/servers/exporthive' row format delimited fields terminated by '\t' collection items terminated by '#' select * from score;

注: 对于集合类型我们使用#来进行分割,因为这个表里面没有集合类型,所以加不加这个结果都一样

二、Hadoop命令导出本地

dfs -get /export/servers/exporthive/000000_0 /export/servers/exporthive/local.txt;

三、hive shell 命令导出

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

bin/hive -e "select * from myhive.score;" > /export/servers/exporthive/score.txt

四、export导出到HDFS上

export table score to '/export/exporthive/score';

五、sqoop导出

六、清空表数据

只能清空管理表,也就是内部表

truncate table score5;