HIVE简单操作
1.hive命令登录HIVE数据库后,执行show databases;命令可以看到hive数据库中有一个默认的default数据库。
[root@hadoop hive]# hive Logging initialized using configuration in file:/usr/local/hive/conf/hive-log4j2.properties Async: true
Hive-on-MR is deprecated in Hive and may not be available in the future versions. Consider using a different execution engine (i.e. spark, tez) or using Hive .X releases.
hive> show databases;
OK
default #可以看到HIVE默认自带了一个数据库default
Time taken: 21.043 seconds, Fetched: row(s)
hive>
然后登录mysql数据库,show databases;显示数据库名,可以看到有一个hive数据库;use hive; 进入hive数据库;show tables;显示表名;select * from DBS; #可以看到HIVE默认default数据库的元数据信息。
[root@hadoop ~]# mysql -uroot -proot
Warning: Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is
Server version: 5.6.-log MySQL Community Server (GPL) Copyright (c) , , Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| hive |
| mysql |
| performance_schema |
| test |
+--------------------+
rows in set (0.32 sec) mysql> use hive
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A Database changed
mysql> show tables;
+---------------------------+
| Tables_in_hive |
+---------------------------+
| AUX_TABLE |
| BUCKETING_COLS |
| CDS |
| COLUMNS_V2 |
| COMPACTION_QUEUE |
| COMPLETED_COMPACTIONS |
| COMPLETED_TXN_COMPONENTS |
| DATABASE_PARAMS |
| DBS |
| DB_PRIVS |
| DELEGATION_TOKENS |
| FUNCS |
| FUNC_RU |
| GLOBAL_PRIVS |
| HIVE_LOCKS |
| IDXS |
| INDEX_PARAMS |
| KEY_CONSTRAINTS |
| MASTER_KEYS |
| NEXT_COMPACTION_QUEUE_ID |
| NEXT_LOCK_ID |
| NEXT_TXN_ID |
| NOTIFICATION_LOG |
| NOTIFICATION_SEQUENCE |
| NUCLEUS_TABLES |
| PARTITIONS |
| PARTITION_EVENTS |
| PARTITION_KEYS |
| PARTITION_KEY_VALS |
| PARTITION_PARAMS |
| PART_COL_PRIVS |
| PART_COL_STATS |
| PART_PRIVS |
| ROLES |
| ROLE_MAP |
| SDS |
| SD_PARAMS |
| SEQUENCE_TABLE |
| SERDES |
| SERDE_PARAMS |
| SKEWED_COL_NAMES |
| SKEWED_COL_VALUE_LOC_MAP |
| SKEWED_STRING_LIST |
| SKEWED_STRING_LIST_VALUES |
| SKEWED_VALUES |
| SORT_COLS |
| TABLE_PARAMS |
| TAB_COL_STATS |
| TBLS |
| TBL_COL_PRIVS |
| TBL_PRIVS |
| TXNS |
| TXN_COMPONENTS |
| TYPES |
| TYPE_FIELDS |
| VERSION |
| WRITE_SET |
+---------------------------+
rows in set (0.00 sec) mysql> select * from DBS; #可以看到HIVE默认数据库default的元数据
+-------+-----------------------+----------------------------------------+---------+------------+------------+
| DB_ID | DESC | DB_LOCATION_URI | NAME | OWNER_NAME | OWNER_TYPE |
+-------+-----------------------+----------------------------------------+---------+------------+------------+
| | Default Hive database | hdfs://hadoop:9000/user/hive/warehouse | default | public | ROLE |
+-------+-----------------------+----------------------------------------+---------+------------+------------+
row in set (0.00 sec) mysql>
2.在hive创建一个测试库
hive> create database testhive; #创建库
OK
Time taken: 3.45 seconds hive> show databases; #显示库
OK
default
testhive
Time taken: 1.123 seconds, Fetched: row(s)
在mysql查看,发现显示了测试库元数据信息(包括testhive的DB_ID,在HDFS上的存储位置等 )
mysql> select * from DBS;
+-------+-----------------------+----------------------------------------------------+----------+------------+------------+
| DB_ID | DESC | DB_LOCATION_URI | NAME | OWNER_NAME | OWNER_TYPE |
+-------+-----------------------+----------------------------------------------------+----------+------------+------------+
| | Default Hive database | hdfs://hadoop:9000/user/hive/warehouse | default | public | ROLE |
| | NULL | hdfs://hadoop:9000/user/hive/warehouse/testhive.db | testhive | root | USER |
+-------+-----------------------+----------------------------------------------------+----------+------------+------------+
rows in set (0.00 sec)
在HDFS查看,我们看一下testhive.db是什么。它其实就是一个目录,所以说创建一个数据库其实就是创建了一个目录
我创建的hdfs目录明明是/usr/hive/warehouse/,不知道为啥数据库却保存到了/user/hive/warehouse/??哪里出错了??或者说是我的目录创建错了,应该创建的就是/user/hive/warehouse/?
[root@hadoop ~]# hdfs dfs -ls /user/hive/warehouse
Found items
drwxr-xr-x - root supergroup -- : /user/hive/warehouse/testhive.db
3.创建表
hive> use testhive; #使用库
OK
Time taken: 0.131 seconds hive> create table test(id int); 创建表
OK
Time taken: 3.509 seconds
在mysql中查看表的信息,可以看到test表归属于DB_ID为6的数据库,即testhive(可 select * from DBS; 查看)
mysql> select * from TBLS;
+--------+-------------+-------+------------------+-------+-----------+-------+----------+---------------+--------------------+--------------------+--------------------+
| TBL_ID | CREATE_TIME | DB_ID | LAST_ACCESS_TIME | OWNER | RETENTION | SD_ID | TBL_NAME | TBL_TYPE | VIEW_EXPANDED_TEXT | VIEW_ORIGINAL_TEXT | IS_REWRITE_ENABLED |
+--------+-------------+-------+------------------+-------+-----------+-------+----------+---------------+--------------------+--------------------+--------------------+
| | | | | root | | | test | MANAGED_TABLE | NULL | NULL | |
+--------+-------------+-------+------------------+-------+-----------+-------+----------+---------------+--------------------+--------------------+--------------------+
row in set (0.01 sec)
在HDFS中查看,发现HDFS为新表创建了一个目录
[root@hadoop ~]# hdfs dfs -ls /user/hive/warehouse/testhive.db
Found items
drwxr-xr-x - root supergroup -- : /user/hive/warehouse/testhive.db/test
4.插入数据。
4.1 在表中插入数据 insert into test values (1); 可以看到系统在对数据进行MapReduce。
hive> insert into test values ();
WARNING: Hive-on-MR is deprecated in Hive and may not be available in the future versions. Consider using a different execution engine (i.e. spark, tez) or using Hive .X releases.
Query ID = root_20180727155527_5971c7d8-9b5c-4ef3-98f7-63febe38c79a
Total jobs =
Launching Job out of
Number of reduce tasks is set to since there's no reduce operator
Starting Job = job_1532671010251_0001, Tracking URL = http://hadoop:8088/proxy/application_1532671010251_0001/
Kill Command = /usr/local/hadoop/bin/hadoop job -kill job_1532671010251_0001
Hadoop job information for Stage-: number of mappers: ; number of reducers:
-- ::, Stage- map = %, reduce = %, Cumulative CPU 3.32 sec
MapReduce Total cumulative CPU time: seconds msec
Ended Job = job_1532671010251_0001
Stage- is selected by condition resolver.
Stage- is filtered out by condition resolver.
Stage- is filtered out by condition resolver.
Moving data to directory hdfs://hadoop:9000/user/hive/warehouse/testhive.db/test/.hive-staging_hive_2018-07-27_15-55-27_353_3121708441542170724-1/-ext-10000
Loading data to table testhive.test
MapReduce Jobs Launched:
Stage-Stage-: Map: Cumulative CPU: 3.32 sec HDFS Read: HDFS Write: SUCCESS
Total MapReduce CPU Time Spent: seconds msec
OK
Time taken: 453.982 seconds
在HDFS查看,发现HDFS将插入的数据封装成了一个文件000000_0
[root@hadoop ~]# hdfs dfs -ls /user/hive/warehouse/testhive.db/test
-rwxr-xr-x root supergroup -- : /user/hive/warehouse/testhive.db/test/000000_0
[root@hadoop ~]# hdfs dfs -cat /user/hive/warehouse/testhive.db/test/000000_0
4.2 再插入一个数据 insert into test values (2); 可以看到系统还是在对数据进行MapReduce。
hive> insert into test values ();
在HDFS中查看,发现HDFS将插入的数据封装成了另外一个文件000000_0_copy_1
[root@hadoop ~]# hdfs dfs -ls /user/hive/warehouse/testhive.db/test
Found items
-rwxr-xr-x root supergroup -- : /user/hive/warehouse/testhive.db/test/000000_0
-rwxr-xr-x root supergroup -- : /user/hive/warehouse/testhive.db/test/000000_0_copy_1
[root@hadoop ~]# hdfs dfs -cat /user/hive/warehouse/testhive.db/test/000000_0_copy_1
4.3 再插入一个数据 insert into test values (3); 可以看到系统还是在对数据进行MapReduce。
在HDFS中查看,发现HDFS将插入的数据封装成了另外一个文件000000_0_copy_2
[root@hadoop ~]# hdfs dfs -ls /user/hive/warehouse/testhive.db/test
Found items
-rwxr-xr-x root supergroup -- : /user/hive/warehouse/testhive.db/test/000000_0
-rwxr-xr-x root supergroup -- : /user/hive/warehouse/testhive.db/test/000000_0_copy_1
-rwxr-xr-x root supergroup -- : /user/hive/warehouse/testhive.db/test/000000_0_copy_2
[root@hadoop ~]# hdfs dfs -cat /user/hive/warehouse/testhive.db/test/000000_0_copy_2
4.4 在hive中查看表
hive> select * from test;
OK 2
3
Time taken: 5.483 seconds, Fetched: row(s)
5.从本地文件加载数据
先创建文件
[root@hadoop ~]# vi hive.txt #创建文件 #保存退出
然后加载数据
hive> load data local inpath '/root/hive.txt' into table testhive.test; #加载数据
Loading data to table testhive.test
OK
Time taken: 6.282 seconds
在hive中查看,发现文件内容被映射到了表中的对应的列里
hive> select * from test;
OK Time taken: 0.534 seconds, Fetched: row(s)
在HDFS查看,发现hive.txt文件被保存到了test表目录下
[root@hadoop ~]# hdfs dfs -ls /user/hive/warehouse/testhive.db/test
Found items
-rwxr-xr-x root supergroup -- : /user/hive/warehouse/testhive.db/test/000000_0
-rwxr-xr-x root supergroup -- : /user/hive/warehouse/testhive.db/test/000000_0_copy_1
-rwxr-xr-x root supergroup -- : /user/hive/warehouse/testhive.db/test/000000_0_copy_2
-rwxr-xr-x root supergroup -- : /user/hive/warehouse/testhive.db/test/hive.txt
6.hive也支持排序 select * from test order by id desc; 可以看到hive此时也是有一个MapReduce过程
hive> select * from test order by id desc;
WARNING: Hive-on-MR is deprecated in Hive and may not be available in the future versions. Consider using a different execution engine (i.e. spark, tez) or using Hive .X releases.
Query ID = root_20180730093619_c798eb69-b94f--94cc-5ec56865ed5c
Total jobs =
Launching Job out of
Number of reduce tasks determined at compile time:
In order to change the average load for a reducer (in bytes):
set hive.exec.reducers.bytes.per.reducer=<number>
In order to limit the maximum number of reducers:
set hive.exec.reducers.max=<number>
In order to set a constant number of reducers:
set mapreduce.job.reduces=<number>
Starting Job = job_1532913019648_0001, Tracking URL = http://hadoop:8088/proxy/application_1532913019648_0001/
Kill Command = /usr/local/hadoop/bin/hadoop job -kill job_1532913019648_0001
Hadoop job information for Stage-: number of mappers: ; number of reducers:
-- ::, Stage- map = %, reduce = %
-- ::, Stage- map = %, reduce = %, Cumulative CPU 1.66 sec
-- ::, Stage- map = %, reduce = %, Cumulative CPU 2.72 sec
-- ::, Stage- map = %, reduce = %, Cumulative CPU 5.41 sec
MapReduce Total cumulative CPU time: seconds msec
Ended Job = job_1532913019648_0001
MapReduce Jobs Launched:
Stage-Stage-: Map: Reduce: Cumulative CPU: 5.93 sec HDFS Read: HDFS Write: SUCCESS
Total MapReduce CPU Time Spent: seconds msec
OK Time taken: 224.27 seconds, Fetched: row(s)
7.hive也支持desc test;
hive> desc test;
OK
id int
Time taken: 6.194 seconds, Fetched: row(s)
hive数据库的操作和mysql其实差不多,它的缺点是没有修改和删除命令,优点是不需要用户亲自写MapReduce,只需要通过简单的sql语句的形式就可以实现复杂关系。
hive的操作还有很多,以后用到再整理吧。
HIVE简单操作的更多相关文章
- x01.MagicCube: 简单操作
看最强大脑,发现魔方还是比较好玩的,便买了一个,对照七步还原法,居然也能成功还原. 为什么不写一个魔方程序呢?在网上找了找,略作修改,进行简单操作,还是不错的,其操作代码如下: protected o ...
- js简单操作Cookie
贴一段js简单操作Cookie的代码: //获取指定名称的cookie的值 function getCookie(objName) { var arrStr = document.cookie.spl ...
- GitHub学习心得之 简单操作
作者:枫雪庭 出处:http://www.cnblogs.com/FengXueTing-px/ 欢迎转载 前言 本文对Github的基本操作进行了总结, 主要基于以下文章: http://gitre ...
- Linq对XML的简单操作
前两章介绍了关于Linq创建.解析SOAP格式的XML,在实际运用中,可能会对xml进行一些其它的操作,比如基础的增删该查,而操作对象首先需要获取对象,针对于DOM操作来说,Linq确实方便了不少,如 ...
- Linux 中 Vi 编辑器的简单操作
Linux 中 Vi 编辑器的简单操作 Vi 编辑器一共有3种模式:命名模式(默认),尾行模式,编辑模式.3种模式彼此需要切换. 一.进入 Vi 编辑器的的命令 vi filename //打开或新 ...
- python(pymysql)之mysql简单操作
一.mysql简单介绍 说到数据库,我们大多想到的是关系型数据库,比如mysql.oracle.sqlserver等等,这些数据库软件在windows上安装都非常的方便,在Linux上如果要安装数据库 ...
- ZooKeeper系列3:ZooKeeper命令、命令行工具及简单操作
问题导读1.ZooKeeper包含哪些常用命令?2.通过什么命令可以列出服务器 watch 的详细信息?3.ZooKeeper包含哪些操作?4.ZooKeeper如何创建zookeeper? 常用命令 ...
- ORACLE的安装与网页版创建表空间的简单操作以及PLsql的简单操作
1.oracle的安装: 安装简单易学,在这里不做解释.下载看装包后耐心等待,注意安装目录不要有中文字符,尽量按照指定目录进行安装.安装完成后会占用有大约5g的内存. 如果要卸载oracle,需要用其 ...
- spark使用Hive表操作
spark Hive表操作 之前很长一段时间是通过hiveServer操作Hive表的,一旦hiveServer宕掉就无法进行操作. 比如说一个修改表分区的操作 一.使用HiveServer的方式 v ...
随机推荐
- JSESSIONID、SESSION、cookie .
所谓session可以这样理解:当与服务端进行会话时,比如说登陆成功后,服务端会为用户开壁一块内存区间,用以存放用户这次会话的一些内容,比如说用户名之类的.那么就需要一个东西来标志这个内存区间是你的而 ...
- 05原型模式Prototype
一.什么是原型模式 Prototype模式是一种对象创建型模式,它采 取复制原型对象的方法来创建对象的实例.使用 Prototype模式创建的实例,具有与原型一样的 数据. 二.原型模式的特点 1. ...
- html div+css做页面布局
http://blog.csdn.net/mercop/article/details/7882000 HTML CSS + DIV实现整体布局 1.技术目标: 开发符合W3C标准的Web页面 理解盒 ...
- Markdown 列表
如下,分别表示无序列表 .有序列表 .待办列表 - Red - Blue - Green . Red . Blue . Green - [ ] 不勾选 - [x] 勾选
- TransmittableThreadLocal 解决 线程池线程复用 无法复制 InheritableThreadLocal 的问题.
ThreadLoacl,InheritableThreadLocal,原理,以及配合线程池使用的一些坑 TransmittableThreadLocal 原理 之前为了能让InheritableThr ...
- Git使用基础篇
Git使用基础篇 前言 Git是一个分布式的版本控制工具,本篇文章从介绍Git开始,重点在于介绍Git的基本命令和使用技巧,让你尝试使用Git的同时,体验到原来一个版 本控制工具可以对开发产生如此之多 ...
- RandomForest中的feature_importance
随机森林算法(RandomForest)的输出有一个变量是 feature_importances_ ,翻译过来是 特征重要性,具体含义是什么,这里试着解释一下. 参考官网和其他资料可以发现,RF可以 ...
- vue 数据管道
文档https://cn.vuejs.org/v2/guide/filters.html html 片段 <div class="app"> <div>{{ ...
- CentOS开机自启动/etc/rc.local不执行的解决办法
放置在开机自启动里面没有自动启动 查看文件/etc/rc.local发现是一个软连接 修改源文件的执行权限即可 chmod 755 /etc/rc.d/rc.local 查看日志可以看到开机自启动过程 ...
- bochs
● 制作一个硬盘 ./bximage 步骤与制作软盘的相似,完成后将bochs软件提示的最后一句话,添加到自己的配置文件里: dd if=loader.bin of=~/Softwares/bochs ...