Hive数据仓库(分析存储在hdfs上面的数据)

本文详细介绍了Hive数据仓库的产生背景、功能特点、元数据存储,以及如何在Hadoop环境下搭建Hive,包括单用户模式和多用户模式的配置。还讲解了Hive的数据类型、表的类型(如单分区和双分区)、动态分区、Hive的执行方式和分桶抽样查询等核心概念和操作。
摘要由CSDN通过智能技术生成

启动命令

[root@node1 conf]# nohup hive --service metastore & nohup是放入后台

Hive的产生

非java编程者对hdfs的数据做mapreduce操作

Hive简介

Hive : 数据仓库。
Hive:解释器,编译器,优化器等。
Hive 运行时,元数据存储在关系型数据库(mysql)里面
在这里插入图片描述

  1. 用户接口主要有三个:CLI(命令行),Client 和 WUI。其中最常用的是CLI,Cli启动的时候,会同时启动一个Hive副本。Client是Hive的客户端,用户连接至Hive Server。在启动 Client模式的时候,需要指出Hive Server所在节点,并且在该节点启动Hive Server。 WUI是通过浏览器访问Hive。
  2. Hive将元数据存储在数据库中,如mysql、derby。Hive中的元数据包括表的名字,表的列和分区及其属性,表的属性(是否为外部表等),表的数据所在目录等。
  3. 解释器、编译器、优化器完成HQL查询语句从词法分析、语法分析、编译、优化以及查询计划的生成。生成的查询计划存储在HDFS中,并在随后有MapReduce调用执行。
  4. Hive的数据存储在HDFS中,大部分的查询、计算由MapReduce完成。
    在这里插入图片描述
    Metastore:Mysq
    Driver:Hive
    Compiler:解释器
    Hadoop:Hadoop 数据来源

Hive搭建

Hive的搭建模式
local模式。
此模式连接到一个In-memory 的数据库Derby,一般用于Unit Test。
Mysql模式:
单用户模式:在这里插入图片描述

多用户模式:
通过网络连接到一个数据库中,是最经常使用到的模式:
远程服务器模式/多用户模式。
用于非Java客户端访问元数据库,在服务器端启动MetaStoreServer,客户端利用Thrift协议通过MetaStoreServer访问元数据库

在这里插入图片描述
[root@node1 ~]# yum -y install mysql-server
[root@node1 ~]# service mysqld start
[root@node1 ~]# chkconfig mysqld on(开机自启动)
进入mysql
[root@node1 ~]# mysql
mysql> show databases;库
mysql> use mysql进入库
mysql> show tables;展示表
mysql> select host,password from user;
在这里插入图片描述

只能本机进入mysql 我们想让node2 node3也能访问

mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '123' WITH GRANT OPTION;

*.*让所有root用户所有ip地址都可以访问mysql密码是123
mysql> delete from user where host!="%";
在这里插入图片描述

Hive单用户模式安装

[root@node1 conf]# pwd
/root/apache-hive-1.2.1-bin/conf
[root@node1 conf]# vi hive-site.xml

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<?xml-stylesheet type="text/xsl" href="configuration.xsl"?><!--
   Licensed to the Apache Software Foundation (ASF) under one or more
   contributor license agreements.  See the NOTICE file distributed with
   this work for additional information regarding copyright ownership.
   The ASF licenses this file to You under the Apache License, Version 2.0
   (the "License"); you may not use this file except in compliance with
   the License.  You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.
-->
<configuration>  
<!--hdfs路径 默认路径-->
<property>  
  <name>hive.metastore.warehouse.dir</name>  
  <value>/user/hive_01/warehouse</value>  
</property>  
<!--连接数据库如果不存在创建 -->
<property>  
  <name>javax.jdo.option.ConnectionURL</name>  
  <value>jdbc:mysql://node1/hive_01?createDatabaseIfNotExist=true</value>  
</property>  
   <!--驱动-->
<property>  
  <name>javax.jdo.option.ConnectionDriverName</name>  
  <value>com.mysql.jdbc.Driver</value>  
</property>  
   
<property>  
  <name>javax.jdo.option.ConnectionUserName</name>  
  <value>root</value>  
</property>  
   
<property>  
  <name>javax.jdo.option.ConnectionPassword</name>  
  <value>123</value>  
</property> 

</configuration>

上传驱动
[root@node1 ~]# mv mysql-connector-java-5.1.32-bin.jar apache-hive-1.2.1-bin/lib/
[root@node1 lib]# pwd
/root/apache-hive-1.2.1-bin/lib
[root@node1 lib]# cp jline-2.12.jar /root/hadoop-2.6.5/share/hadoop/yarn/lib/
[root@node1 lib]# pwd
/root/hadoop-2.6.5/share/hadoop/yarn/lib
[root@node1 lib]# rm -rf jline-0.9.94.jar
[root@node1 ~]# vi .bash_profile

#hive
export HIVE_HOME=/root/apache-hive-1.2.1-bin
export PATH=$PATH:$HIVE_HOME/bin

[root@node1 ~]# source .bash_profile
[root@node1 ~]# hive 可以进去

多用户配置

[root@node1 conf]# pwd
/root/apache-hive-1.2.1-bin/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值