#从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. [Solution] AOP原理解析及Castle、Autofac、Unity框架使用

    本节目录: AOP介绍 AOP基本原理 AOP框架 Castle Core Castle Windsor Autofac Unity AOP介绍 面向切面编程(Aspect Oriented Prog ...

  2. Linux - root初始密码设置

    Ubuntu刚安装后,不能在terminal中运行su命令,因为root没有默认密码,需要手动设定. 以安装ubuntu时输入的用户名登陆,该用户在admin组中,有权限给root设定密码. 给roo ...

  3. 【循序渐进学Python】6.Python中的函数

    1. 创建函数 一个函数代表一个行为并且返回一个结果(包括None),在Python中使用def关键字来定义一个函数,如下: def hello(name): print 'hello,' + nam ...

  4. GridView 使用方法总结 (一)

    GridView 使用方法总结 (一) 下载全部代码 http://www.sufeinet.com/thread-431-1-1.html   原文件作者是:csdn.net的清清月儿 她的主页  ...

  5. Studio for WPF:使用 C1TileView 创建图片库

    C1TileView 提供了数据交互浏览的功能.允许我们设置最大化和最小化浏览模板,我们可以通过最小化模板快速定位详细浏览选项. 下面我们分步分享实现方法: 1.添加 C1TileView 到窗体,并 ...

  6. vmware screen

    1. Question Description: the screen of the vmware looks small . 2. Solution: 2.1 look the size of sc ...

  7. 【Android】Android SDK Manager更新慢/失败的问题

    前言:更新下载Intel x86 Atom_64 System Image的时候总是失败,速度只有几KB,我这是10M的网啊. 最后找到一篇日志,解决了这个问题.非常感谢!其参考地址:http://w ...

  8. MaterialRefreshLayout

    以上就介绍了比SwipeRefreshLayout更漂亮和强大的下拉刷新控件:Android-MaterialRefreshLayout 1.xml <?xml version="1. ...

  9. [Angularjs]视图和路由(四)

    写在前面 关于angularjs的路由的概念基本上这篇就要结束了,通过学习,以及在实际项目中的实践,还是比较容易上手的.自己也通过angularjs做了一个在app上的一个模块,效果还是可以的. 系列 ...

  10. 移动端调试工具-Debuggap

    随着移动互联网的迅速崛起,开发移动应用程序越来越多,但如果在移动端开发应用程序需要调试时,额- 仿佛又回到了IE时代,最方便也只能到处 alert 来调试.目前已经有一款产品可以做到这一点,比如pho ...