#从hive中直接进入hdfs的daas/bstl/term/userinfo目录下

hive> !hadoop fs -ls /daas/bstl/term/userinfo;

查看hive表结构以及对应的hdfs的路径

hive> desc formatted 表名;

1.
Hive的几种常见的数据导入方式
这里介绍四种:
(1)、从本地文件系统中导入数据到Hive表;
(2)、从HDFS上导入数据到Hive表;
(3)、从别的表中查询出相应的数据并导入到Hive表中;
(4)、在创建表的时候通过从别的表中查询出相应的记录并插入到所创建的表中

1.从本地文件系统中导入数据到Hive表
1.1
[hadoop@h91 hive-0.9.0-bin]$ bin/hive
创建ha表
hive> create table ha(id int,name string)
> row format delimited
> fields terminated by '\t'
> stored as textfile;

[ROW FORMAT DELIMITED]关键字,是用来设置创建的表在加载数据的时候,支持的列分隔符。
[STORED AS file_format]关键字是用来设置加载数据的数据类型,默认是TEXTFILE,如果文件数据是纯文本,就是使用 [STORED AS TEXTFILE],然后从本地直接拷贝到HDFS上,hive直接可以识别数据。

1.2
操作系统中的文本
[hadoop@h91 ~]$ cat haha.txt
101 zs
102 ls
103 ww

1.3导入数据
hive> load data local inpath '/home/hadoop/haha.txt' into table ha;
hive> select * from ha;

*****
和我们熟悉的关系型数据库不一样,Hive现在还不支持在insert语句里面直接给出一组记录的文字形式,也就是说,Hive并不支持INSERT INTO …. VALUES形式的语句。
*****

--------------------------------------------------
2.
从HDFS上导入数据到Hive表;

2.1
[hadoop@h91 hadoop-0.20.2-cdh3u5]$ bin/hadoop fs -mkdir abc

[hadoop@h91 ~]$ cat hehe.txt
1001 aa
1002 bb
1003 cc

[hadoop@h91 hadoop-0.20.2-cdh3u5]$ bin/hadoop fs -put /home/hadoop/hehe.txt abc/.
(上传到 hdfs中)

2.2
hive> create table he(id int,name string)
> row format delimited
> fields terminated by '\t'
> stored as textfile;

导入
hive> load data inpath '/user/hadoop/abc/hehe.txt' into table he;

---------------------------------------------------------
3.从别的表中查询出相应的数据并导入到Hive表中

3.1
hive> select * from he;
OK
1001 aa
1002 bb
1003 cc

hive> create table heihei(id int,name string)
> row format delimited
> fields terminated by '\t'
> stored as textfile;

3.2
hive> insert into table heihei select * from he;


hive> insert overwrite table heihei select * from ha;
(insert overwrite 会覆盖数据)

--------------------------------------------------
4.在创建表的时候通过从别的表中查询出相应的记录并插入到所创建的表中
hive> create table gaga as select * from he;

================================================================
导出数据
(1)、导出到本地文件系统;
(2)、导出到HDFS中;
(3)、导出到Hive的另一个表中。

1.导出到本地文件系统;
hive> insert overwrite local directory '/home/hadoop/he1' select * from he;

[hadoop@h91 ~]$ cd he1(he1为目录,目录下有000000_0文件 )
[hadoop@h91 he1]$ cat 000000_0
(发现 列之间没有分割 )

可以下面的方式增加分割
hive> insert overwrite local directory '/home/hadoop/he1' select id,concat('\t',name) from he;

******
和导入数据到Hive不一样,不能用insert into来将数据导出
******

---------------------------------------------------------
2.导出到HDFS中。
hive> insert overwrite directory '/user/hadoop/abc' select * from he;
(/user/hadoop/abc 为hdfs下目录)

[hadoop@h91 hadoop-0.20.2-cdh3u5]$ bin/hadoop fs -ls abc
[hadoop@h91 hadoop-0.20.2-cdh3u5]$ bin/hadoop fs -cat abc/000000_0

-------------------------------------------------------------
3.导出到Hive的另一个表中
hive> insert into table he12 select * from he;

hive的常用命令的更多相关文章

  1. 二、hive shell常用命令

    在使用hive shell之前我们需要先安装hive,并启动hdfs 请参考:https://www.cnblogs.com/lay2017/p/9973298.html hive shell 我们先 ...

  2. hive\hadoop 常用命令

    —1—————— 后台跑程序语句: 在shell下输入: nohup hive -f  aaa.sql >bbb.log 2>&1 & 然后把sql 的脚本导入服务器上:T ...

  3. Hive记录-impala常用命令

    1.impala是什么 Impala是Cloudera公司主导开发的新型查询系统,它提供SQL语义,能查询存储在Hadoop的HDFS和HBase中的PB级大数据.已有的Hive系统虽然也提供了SQL ...

  4. Hive记录-Sqoop常用命令

    1.sqoop是什么 Sqoop是一款开源的数据迁移工具,主要用于Hadoop(Hive)与传统的关系型数据库(mysql...)相互之间的数据迁移. 2.sqoop的特点 sqoop的底层实现是ma ...

  5. Hive 常用命令和语句

    示例数据库为 db_hive 1. 创建表 create-table.sql create table if not exists db_hive.tb_user ( id int, username ...

  6. Hive的基本概念和常用命令

    原文链接: https://www.toutiao.com/i6766571623727235595/?group_id=6766571623727235595 一.概念: 1.结构化和非结构化数据 ...

  7. Hive 常用命令

    1.hive模糊搜索表 show tables like '*name*'; 2.查看表结构信息  desc formatted table_name;  desc table_name; 3.查看分 ...

  8. 大数据每日干货第四天(linux基础之一目录结构与常用命令)

           为了和qq空间同步,也写的第四天,前面几天明天会发布,本来打算把每天学的东西记录下来,通过朋友给的建议要发的话稍微系统化下,从大数据需要的linux基础,到离线数据分析包括hadoop. ...

  9. (转)Hbase shell 常用命令(1)

    Hbase shell 常用命令(1) link:http://blog.csdn.net/scutshuxue/article/details/6988348 下面我们看看HBase Shell的一 ...

随机推荐

  1. [Tool] Visual Studio必备插件 + 技能

    总结自己常用的VS插件,其中部分需要注册. 在该链接http://www.cnblogs.com/neverc/p/4591501.html中提供 1.Web Essentials(测试支持2010, ...

  2. Android --- 斗地主 [牌桌实现源码]

    1.主Activity <span style="font-size:18px;color:#3333ff;">package com.bison; import an ...

  3. Python记录-Pip安装

    1.第一步 下载py文件:https://bootstrap.pypa.io/ez_setup.py #!/usr/bin/env python """ Setuptoo ...

  4. C# 通用验证类 支持 WPF,MVC,Winform

    验证方式,   通过继承 IDataErrorInfo接口 和 DataAnnotations 解释标记语言而实现, 为了能在WPF上通用,所了也要继承属性更改通知接口INotifyPropertyC ...

  5. 单例(C#版)

    单例: 一个类只有一个实例.巧妙利用了编程语言的一些语法规则:构造函数private, 然后提供一个public的方法返回类的一个实例:又方法和返回的类的实例都是static类型,所以只能被类所拥有, ...

  6. ActiveReports 报表应用教程 (1)---Hello ActiveReports

    在开始专题内容之前,我们还是了解一下 ActiveReports 是一款什么产品:ActiveReports是一款在全球范围内应用非常广泛的报表控件,以提供.NET报表所需的全部报表设计功能领先于同类 ...

  7. 利用PBfunc在Powerbuilder中使用https获取微信的AccessToken

    在前篇中讲解了使用PBFunc在Powerbuilder自己进行http的GET和POST操作. 本篇简单用代码演示下https的微信AccessToken的获取: n_pbfunc_http lnv ...

  8. 【iOS】Quartz2D矩阵操作

    前面画基本图形时,画四边形是由几条直线拼接成的,现在有更简便的方法. 一.关于矩阵操作 1.画一个四边形 通过设置两个端点(长和宽)来完成一个四边形的绘制. 代码: - (void)drawRect: ...

  9. HTML Jquery

    在<网页制作Dreamweaver(悬浮动态分层导航)>中,运用到了jQuery的技术,轻松实现了菜单的下拉.显示.隐藏的效果,不必再用样式表一点点地修改,省去了很多麻烦,那么jQuery ...

  10. css3实现动态圆形导航栏

    核心问题: 1.圆形怎样实现? css3的圆角属性:border-radius:__ px; 把值设大点就圆啦. 2.怎样实现动画效果? css3的transition属性:transition:__ ...