关于数据库:Windows下Hive环境搭建教程

1次阅读

共计 3266 个字符,预计需要花费 9 分钟才能阅读完成。

前言:

Hive 是一个基于 Hadoop 的数据仓库工具,以一品种 SQL 的 HQL 语句操作 Hadoop 数据仓库 (HDFS 等)。所以本地 windows 装置前须要先搭建 Hadoop。后面文章曾经大略介绍了环境搭建和踩坑汇总,所以这里也仍旧只是介绍根底的装置办法。因为对于 Hive 的装置,网上其实有很多文章,这里更多的是小北在装置过程中的遇到的各种坑的汇总以及解决办法。

环境:

  1. windows10
  2. hadoop2.7.7
    3. mysql-connector-java-5.1.7-bin.jar
    4. hive2.1.1

繁难装置:

  1. Hadoop 本地搭建,略过。
  2. Hive 下载安装,环境变量配置,略过。
    3. Hive config 配置。
    (1). 找到 hive 的 conf 下的以下四个文件再按上面形式批改。
  3. 创立目录。
    (1). 先将 mysql-connector-java-5.1.7-bin.jar 文件挪动到 hive 的 lib 中,如下。

(2). 当初 hive 根目录下创立一个 my_hive 再创立以下四个目录。

  1. 批改 hive-env.sh
    (1). 找到 hive 的 conf 下的 hive-env.sh 并增加以下几个配置。
  1. 批改 hive-site.xml
    (1). 找到 hive 的 conf 下的 hive-site.xml。
    (2). 批改以下几个选项。
<property>
    <name>hive.exec.local.scratchdir</name>
    <value>${java.io.tmpdir}/${user.name}</value>
    <description>Local scratch space for Hive jobs</description>
</property>

<property>
    <name>hive.downloaded.resources.dir</name>
    <value>E:/2setsoft/1dev/apache-hive-2.1.1/my_hive/resources_dir/${hive.session.id}_resources</value>
    <description>Temporary local directory for added resources in the remote file system.</description>
  </property>

<property>
    <name>javax.jdo.option.ConnectionURL</name>
    <value>jdbc:mysql://localhost:3306/hive?characterEncoding=UTF-8&amp;createDatabaseIfNotExist=true</value>
    <description>
      JDBC connect string for a JDBC metastore.
      To use SSL to encrypt/authenticate the connection, provide database-specific SSL flag in the connection URL.
      For example, jdbc:postgresql://myhost/db?ssl=true for postgres database.
    </description>
  </property>

 <property>
    <name>javax.jdo.option.ConnectionDriverName</name>
    <value>com.mysql.jdbc.Driver</value>
    <description>Driver class name for a JDBC metastore</description>
  </property>

  <property>
    <name>javax.jdo.option.ConnectionUserName</name>
    <value>root</value>
    <description>Username to use against metastore database</description>
  </property>

<property>
    <name>javax.jdo.option.ConnectionPassword</name>
    <value>root</value>
    <description>password to use against metastore database</description>
  </property>
  1. 在 Hadopp 上创立 HDFS 目录
    (1). 创立以下目录并授予 777 权限。

(2). 在 hadoop 管制台上查看。

8. 创立 MySQL 数据库
(1). 创立 hive 数据库,能够以命令或者 navicat 形式创立。create database if not exists hive default character set latin1;

  1. 启动 Hive metastore
    (1). 装置结束只须要启动一次,启动后 Mysql 的 hive 数据库会多出以下表格。
    hive –service metastore
  1. 启动 hive
    (1). 如果配置了 hive 环境变量,如果没有则进入 hive 目录的 bin 文件下,输出 hive。
    (2). 启动胜利没有报错,示例创立一张表格,输出以下 HQL 语句创立。create table stu(id int, name string)
    (3). 进入 hadoop 的控制台就能够查看了。
  1. HQL 几个常见命令 hive

启动 hive

show databases;
查看所有数据库

use default;
关上指定数据库

show tables;
依据指定的数据库下展现所有数据表

desc movie;
查看 movie 表构造

create movie(id int, name string);
创立了一个有 id 和 name 两个字段的表格

quit;
退出 hive 

报错合集

  1. HiveConf of name hive.metastore.local does not exist
    去除 <property> <name> hive.metastore.local </name> <value>true</value> </property>
  2. Version information not found in metastore. hive.metastore.schema.verification is not enabled so recording the schema version 2.1.0 在 hive 数据库的 version 增加一条记录,如下
  3. applying authorization policy on hive configuration: java.net.URISyntaxException: Relative path in absolute URI: ${system:java.io.tmpdir%7D/$%7Bsystem:user.name%7D Beeline version 2.1.1 by Apache Hive 关上 hive-site.xml,找到 hive.exec.local.scratchdir, 将带有 system: 的标识全副去掉,如下
  1. hadoop 的 web 控制台文件系统,关上某个目录报错:Permission denied: user=dr.who, access=READ_EXECUTE, inode=”/tmp/hive/Administrator”:Administrator:supergroup:drwx—— 进入 hadoop 命令,输出 hadoop fs -chmod 777 /tmp/hive

Default 数据仓库默认地位:hdfs 上的:/user/hive/warehouse 门路下

<property>
    <name>hive.metastore.warehouse.dir</name>
    <value>/user/hive/warehouse</value>
    <description>location of default database for the warehouse</description>
</property>

正文完
 0