--------------------------------------------数据导入--------------------------------------------------
1.直接向分区表中插入数据(强烈不推荐使用,会调用MR程序,非常慢)
insert into table score3 partition(month ='201807') values ('001','002','100');
2.通过load方式加载数据
load data local inpath '/export/servers/hivedatas/score.csv' overwrite into table score partition(month='201806');
3.通过查询方式加载数据
insert overwrite table score4 partition(month = '201806') select s_id,c_id,s_score from score;
4.多插入模式(from table提前 insert into A部分 select A部分 insert into B部分 select B部分)
将一张表分别插入到两张表里,拆表的时候可以使用
from score insert overwrite table score_first partition(month='201806') select s_id,c_id insert overwrite table score_second partition(month = '201806') select c_id,s_score;
5.将查询的结果保存到一张表当中去
create table score5 as select * from score;
6.创建表时通过location指定加载数据路径(建表时就指定要加载的数据文件的位置)
create external table score6 (s_id string,c_id string,s_score int) row format delimited fields terminated by '\t' location '/myscore6';
此外部表因为指定了数据文件的位置,如果此时上传数据文件,score6就会有对应数据
7.export导出与import 导入 hive表数据(内部表操作)
先将techer的数据文件导出
export table techer to '/export/techer';
再将导出的数据文件导入到techer2中,要保证表结构
import table techer2 from '/export/techer';
8.数据导出(了解)
1.将查询的结果导出到本地
insert overwrite local directory '/export/servers/exporthive' select * from score;
2.将查询的结果格式化导出到本地
insert overwrite local directory '/export/servers/exporthive' row format delimited fields terminated by '\t' collection items terminated by '#' select * from student;
3.将查询的结果导出到HDFS上(没有local)
insert overwrite directory '/export/servers/exporthive' row format delimited fields terminated by '\t' collection items terminated by '#' select * from score;
4.Hadoop命令导出到本地(在hive命令窗口不用hdfs dfs直接dfs执行hadoop命令)
dfs -get /export/servers/exporthive/000000_0 /export/servers/exporthive/local.txt;
5.hive shell 命令导出(本质命令是一样的只是用了命令和文件的方式去执行)
基本语法:(hive -f/-e 执行语句或者脚本 > file)
bin/hive -e "select * from myhive.score;" > /export/servers/exporthive/score.txt
此处管道>重定向直接将结果输出到/export/servers/exporthive/score.txt文件中。