---
title: 启动与验证Hive
description: "1. 启动Hive前的准备工作。"
url: https://www.hikunpeng.com/document/detail/zh/kunpengbds/ecosystemEnable/Hive/topic_0200575958.html
sourcePath: /source/zh/kunpengbds/ecosystemEnable/Hive/topic_0200575958.html
indexId: 316f3a419c0a46c97ff26604289704eaf933e64b7f59df1b4356143af440d39364
---
# 启动与验证Hive

1. 启动Hive前的准备工作。

  a. 下载JDBC。
    下载对应的JDBC驱动(https://downloads.mysql.com/archives/get/p/3/file/mysql-connector-java-5.1.49.tar.gz)
    ，并放置于“/usr/local/hive/lib”
    目录，本次部署选择mysql-connector-java.jar。

```
tar -zxf mysql-connector-java-5.1.49.tar.gz
mv mysql-connector-java-5.1.49.jar /usr/local/hive/lib/
```


  b. 创建Hive数据存放目录。
    1 2 3 4 hdfs dfs -mkdir /tmp hdfs dfs -mkdir -p /user/hive/warehouse hdfs dfs -chmod g+w /tmp hdfs dfs -chmod g+w /user/hive/warehouse

  c. 创建Hive日志目录。
    1 2 3 mkdir -p /usr/local/hive/log/ touch /usr/local/hive/log/hiveserver2.log touch /usr/local/hive/log/hiveserver2.err

2. 初始化Hive。
  1 schematool -dbType mysql -initSchema

3. 启动Hive Metastore。
  1 nohup hive --service metastore -p 9083 &

4. 启动HiveServer2。

  a. 启动。
    1 nohup hiveserver2 1>/usr/local/hive/log/hiveserver2.log 2>/usr/local/hive/log/hiveserver2.err &

  b. 查看启动进度。
    1 tail -f /usr/local/hive/log/hiveserver2.err

    1 2 3 4 5 6 7 8 9 10 11 12 13 nohup: ignoring input which: no hbase in (/usr/local/hadoop/bin:/usr/local/hadoop/sbin:/usr/local/hive/bin:/usr/local/zookeeper/bin:/usr/local/jdk8u222-b10/bin:/usr/local/python3/bin:/usr/local/hadoop/bin:/usr/local/hadoop/sbin:/usr/local/hive/bin:/usr/local/zookeeper/bin:/usr/local/jdk8u222-b10/bin:/usr/local/python3/bin:/usr/local/hadoop/bin:/usr/local/hadoop/sbin:/usr/local/zookeeper/bin:/usr/local/jdk8u222-b10/bin:/usr/local/python3/bin:/usr/local/jdk8u222-b10/bin:/usr/local/python3/bin:/usr/lib64/qt-3.3/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin) 2021-01-18 11:32:22: Starting HiveServer2 SLF4J: Class path contains multiple SLF4J bindings. SLF4J: Found binding in [jar:file:/usr/local/apache-hive-3.1.0-bin/lib/log4j-slf4j-impl-2.10.0.jar!/org/slf4j/impl/StaticLoggerBinder.class] SLF4J: Found binding in [jar:file:/usr/local/hadoop-3.1.1/share/hadoop/common/lib/slf4j-log4j12-1.7.25.jar!/org/slf4j/impl/StaticLoggerBinder.class] SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation. SLF4J: Actual binding is of type [org.apache.logging.slf4j.Log4jLoggerFactory] Hive Session ID = 824030a3-2afe-488c-a2fa-7d98cfc8f7bd Hive Session ID = 1031e326-2088-4025-b2e2-c9bb1e81b03d Hive Session ID = 32203873-49ad-44b7-987c-da1aae8b3375 Hive Session ID = d7be9389-11c6-46cb-90d6-a91a2d5199b8 OK

  c. 查看端口。HiveServer2的默认端口号为10000。
    1 netstat -anp|grep 10000

    如下所示即为启动成功。

    1 tcp6 0 0 :::10000 :::* LISTEN 27800/java

  d. 在server1使用beeline连接。
    1 beeline -u jdbc:hive2://server1:10000 -n root

    回显信息如下。

    1 2 3 4 5 6 7 8 9 10 11 SLF4J: Class path contains multiple SLF4J bindings. SLF4J: Found binding in [jar:file:/usr/local/apache-hive-3.1.0-bin/lib/log4j-slf4j-impl-2.10.0.jar!/org/slf4j/impl/StaticLoggerBinder.class] SLF4J: Found binding in [jar:file:/usr/local/hadoop-3.1.1/share/hadoop/common/lib/slf4j-log4j12-1.7.25.jar!/org/slf4j/impl/StaticLoggerBinder.class] SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation. SLF4J: Actual binding is of type [org.apache.logging.slf4j.Log4jLoggerFactory] Connecting to jdbc:hive2://server1:10000 Connected to: Apache Hive (version 3.1.0) Driver: Hive JDBC (version 3.1.0) Transaction isolation: TRANSACTION_REPEATABLE_READ Beeline version 3.1.0 by Apache Hive 0: jdbc:hive2://server1:10000>

5. 查看已创建的数据库。
  1 show databases;

  如下所示，即Hive启动正常成功。

  1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 0: jdbc:hive2://server1:10000> show databases; INFO : Compiling command(queryId=root_20210118113531_49c3505a-80e1-4aba-9761-c2f77a06ac5f): show databases INFO : Concurrency mode is disabled, not creating a lock manager INFO : Semantic Analysis Completed (retrial = false) INFO : Returning Hive schema: Schema(fieldSchemas:[FieldSchema(name:database_name, type:string, comment:from deserializer)], properties:null) INFO : Completed compiling command(queryId=root_20210118113531_49c3505a-80e1-4aba-9761-c2f77a06ac5f); Time taken: 0.903 seconds INFO : Concurrency mode is disabled, not creating a lock manager INFO : Executing command(queryId=root_20210118113531_49c3505a-80e1-4aba-9761-c2f77a06ac5f): show databases INFO : Starting task [Stage-0:DDL] in serial mode INFO : Completed executing command(queryId=root_20210118113531_49c3505a-80e1-4aba-9761-c2f77a06ac5f); Time taken: 0.029 seconds INFO : OK INFO : Concurrency mode is disabled, not creating a lock manager +----------------+ | database_name | +----------------+ | default | +----------------+ 1 row selected (1.248 seconds)

6. 验证Tez功能。

  a. 使用Tez引擎。
    1 set hive.execution.engine=tez;

  b. 创建student表。
    1 create table student(id int, name string);

  c. 向表中插入数据。
    1 2 insert into student values(1,"zhangsan"); insert into student values(2,"lisi");

  d. 查询student表，如下图所示，查询结果无误即安装成功。
    1 select * from student;

7. 退出Hive界面。
  1 !quit

  如果是使用beeline -u jdbc:hive2://agent1:10000 -n root命令进入Hive数据库，使用!quit退出。 如果是使用hive命令进入Hive数据库，则使用quit;退出。
