hive库装载和导出数据总结

      把数据装载到hive库一般有两种,一种是通过etl抽取数据然后装载数据到hive,一种是文件装载到hive库,导出hive库也有两种方式,一种是直接装载到传统库,一种是生成文件之后再装载到传统库,如下所示:

《hive库装载和导出数据总结》 数据流程图

文件导入导出:

1. 从本地文件系统装载到hive表

load data local inpath ‘aaa.txt’ into table hive_test_table partition(op_time=20170212,op_hour=2017021222);

或者:

put aaa.txt /hive_test_table/op_time=20170212/op_hour=2017021222;

2.hdfs文件导入到hive表

load data inpath ‘/hive_test_table/op_time=20170212/op_hour=2017021222/aaa.txt’ into table hive_test_table;

3.从hive库导出文件到本地文件系统

insert overwrite local directory ‘/data8/demo’ row format delimited fields terminated by ‘^’  select * from test_hive_table where op_month= 201701 and op_time= 20170111 and op_hour= 2017011111 ;

sqoop数据导入导出:

1.mysql数据库数据导入hive库

sqoop import –connect jdbc:mysql://ip:端口/sqoop –username 用户名 –password 密码–table mysql表 -m 1

2.hive数据导入到mysql数据库

sqoop export –connect jdbc:mysql://ip:端口/sqoop –username 用户名 –password 密码–table mysql表 –export-dir hdfs:/user/warehouse/students/00000_00

3.oracle数据导入hive库

sqoop import –hive-import –connect jdbc:oracle:thin:@ip:端口:数据库 –username 用户名 –password 密码 –verbose -m 1 –table 表名

注:并发数设置为1

hive库表与表之间的导入:

insert into hive_test_table partition(op_time=20170212,op_hour=2017021222) select * from hive_test_table_1;

    原文作者:DJ_2017
    原文地址: https://www.jianshu.com/p/fb911c8f5977
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞