hive的常用命令
#从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的常用命令的更多相关文章
- 二、hive shell常用命令
在使用hive shell之前我们需要先安装hive,并启动hdfs 请参考:https://www.cnblogs.com/lay2017/p/9973298.html hive shell 我们先 ...
- hive\hadoop 常用命令
—1—————— 后台跑程序语句: 在shell下输入: nohup hive -f aaa.sql >bbb.log 2>&1 & 然后把sql 的脚本导入服务器上:T ...
- Hive记录-impala常用命令
1.impala是什么 Impala是Cloudera公司主导开发的新型查询系统,它提供SQL语义,能查询存储在Hadoop的HDFS和HBase中的PB级大数据.已有的Hive系统虽然也提供了SQL ...
- Hive记录-Sqoop常用命令
1.sqoop是什么 Sqoop是一款开源的数据迁移工具,主要用于Hadoop(Hive)与传统的关系型数据库(mysql...)相互之间的数据迁移. 2.sqoop的特点 sqoop的底层实现是ma ...
- Hive 常用命令和语句
示例数据库为 db_hive 1. 创建表 create-table.sql create table if not exists db_hive.tb_user ( id int, username ...
- Hive的基本概念和常用命令
原文链接: https://www.toutiao.com/i6766571623727235595/?group_id=6766571623727235595 一.概念: 1.结构化和非结构化数据 ...
- Hive 常用命令
1.hive模糊搜索表 show tables like '*name*'; 2.查看表结构信息 desc formatted table_name; desc table_name; 3.查看分 ...
- 大数据每日干货第四天(linux基础之一目录结构与常用命令)
为了和qq空间同步,也写的第四天,前面几天明天会发布,本来打算把每天学的东西记录下来,通过朋友给的建议要发的话稍微系统化下,从大数据需要的linux基础,到离线数据分析包括hadoop. ...
- (转)Hbase shell 常用命令(1)
Hbase shell 常用命令(1) link:http://blog.csdn.net/scutshuxue/article/details/6988348 下面我们看看HBase Shell的一 ...
随机推荐
- jQuery的 delegate问题
习惯了bind,用惯了live,就不习惯delegate了呀有木有... 支持为动态生成的标签元素绑定事件也许就live和delegate了吧,不过新版本已经不支持live了,只有delegate d ...
- EntityFramework 6.1.2-beta2
EntityFramework 6.1.2-beta2 Entity Framework is Microsoft's recommended data access technology for n ...
- ADO.NET 增 删 改 查
ADO.NET:(数据访问技术)就是将C#和MSSQL连接起来的一个纽带 可以通过ADO.NET将内存中的临时数据写入到数据库中 也可以将数据库中的数据提取到内存中供程序调用 ADO.NET所有数据访 ...
- 【转】Aspose.Cells读取excel文件
Aspose是一个很强大的控件,可以用来操作word,excel,ppt等文件,用这个控件来导入.导出数据非常方便.其中Aspose.Cells就是用来操作Excel的,功能有很多.我所用的是最基本的 ...
- sencha gridpanel 单元格编辑
{ xtype: 'gridpanel', region: 'north', height: 150, title: 'My Grid Panel', store: 'A_Test_Store', c ...
- Hadoop Pipes Exception: Illegal text protocol command
Hadoop Pipes Exception: Illegal text protocol command 对于Hadoop pipes 出现这样的错误,基本上编译代码依赖的.so和.a 版本不匹配 ...
- ASP.NET WebAPI 13 Filter
Filter(筛选器)是基于AOP(面向方面编程)的设计,它的作用是Actionr的执行注入额外的逻辑,以达到横切注入的目的. IFilter 在WebAPI中所以的Filter都实现了IFilter ...
- 对抗静态分析——so文件的加密
[预备起~~~]最近在忙找工作的事情,笔试~面试~笔试~面试...很久没有写(pian)文(gao)章(fei).忙了一阵子之后,终于~~~到了选offer的阶段(你家公司不是牛吗,老子不接你家off ...
- vsphere vcenter server下安装ubuntu的vmwaretools
0.参考文献 百度经验:这里面是以redhat桌面版为实例进行介绍的,我的环境是ubuntu-server,虽然不一样,也可以参考 http://jingyan.baidu.com/article/2 ...
- Android-ListView类
ListView组件在应用程序中可以说是不可或缺的一部分,ListView主要是显示列表数据,同时可以滚动查看,这篇博客主要是对ListView的基本用法进行说明,后面会依次对ListView点击动态 ...