hive导入导出数据汇总

文章详细介绍了Hive中数据的导入和导出方法,包括从本地磁盘和HDFS导入数据,使用loaddata和insert语句,以及export和import命令进行集群间表迁移。此外,还提到了使用dfs命令、hiveshell和sqoop进行数据操作的方式。
摘要由CSDN通过智能技术生成

一,hive导入数据方式

  1. load数据方式
    1.1 从本地磁盘导入:
    load data local inpath ‘/localpath’ into table table1; #最加的方式
    load data local inpath ‘/opt/mydata.csv’ overwrite into table table1; #覆写的方式

1.2 从HDFS导入(无关键字local):
load data inpath ‘/localpath’ into table table1; #最加的方式
load data inpath ‘/localpath’ overwrite into table table1; #覆写的方式

  1. 表操作方式
    2.1 insert into … select
    insert into table1 select id,name from table1; #最加的方式
    insert overwrite into table1 select id,name from table1; #覆写的方式

2.1 create … as select
create table1 as select * from table2 where 1=1;

  1. import导入方式
    import table student2 from ‘/user/hive/warehouse/export/student’;
    #注意:import只能导入export命令从Hive到出去的数据,且目标表可以为空,如果已经创建则必须是空表

  2. 建hive外表的方式location导入数据(注意建表时分隔符)
    create external table if not exists student5( id int, name string) row format delimited fields terminated by ‘\t’ location '/student;

  3. sqoop导入(略)
    具体查看sqoop导入方式;

二,hive导出数据方式
1,insert导出方式
导出到本地文件:
insert overwrite local directory ‘/opt/module/hive/data/export/student’
ROW FORMAT DELIMITED FIELDS TERMINATED BY ‘\t’ #指定分隔符为空格
select * from student;

导出到HDFS文件系统(无local关键字):
insert overwrite directory ‘/opt/module/hive/data/export/student’
ROW FORMAT DELIMITED FIELDS TERMINATED BY ‘\t’
select * from student;

2,dfs导出方式(注意hive建表必须时textfile格式)
#类似于hdfs导出方式
dfs -get /tmp/student.txt /tmp/student.txt;

3,export
export 和 import 主要用于两个 Hadoop 平台集群之间 Hive 表迁移。
export table ds.table1 to ‘/tmp/export/table1’;

4,hive shell(hive -e/-f)
hive shell执行sql语句,结果存储到文件
bin/hive -e ‘select * from ds.table1;’ > /tmp/export/table1.txt;

hive shell执行sql文件,结果存储到文件
bin/hive -f hivesql1.sql > /tmp/export/table1.txt;

5,sqoop导出(略)
具体查看sqoop导出方式;

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值