Hive 3.1.1安装与配置

前言:hive的水贼深,安装其他教程安装报了很多错。如果有错误的地方,欢迎大家留言。

环境

linux18.04
Hadoop3.2.0
mysql8.0.12
hive3.1.1

安装Mysql

在Linux上安装mysql
之前的博客写过mysql的安装了。这里不再赘述。

下载hive

直接在官网载
http://www.apache.org/dyn/closer.cgi/hive/

配置环境变量

编辑etc/profile

sudo vim /etc/profile

我直接将我的复制出来了,还有java和hadoop的环境变量

export JAVA_HOME=/usr/lib/jdk/jdk1.8.0_201
export JRE_HOME=${JAVA_HOME}/jre
export CLASSPATH=.:${JAVA_HOME}/lib:${JRE_HOME}/lib
export HADOOP_HOME=/home/czq/hadoop/hadoop-3.2.0
export HIVE_HOME=/home/czq/hive/apache-hive-3.1.1-bin
export PATH=$PATH:$JAVA_HOME/bin:$HADOOP_HOME/bin:$HADOOP_HOME/sbin:$HIVE_HOME/bin

使其生效

source /etc/profile

配置

hive-env.sh
首先配置hive-env.sh

#hadoop根目录
HADOOP_HOME=/home/czq/hadoop/hadoop-3.2.0
#hive配置文件目录  
export HIVE_CONF_DIR=/home/czq/hive/apache-hive-3.1.1-bin/conf
#hive依赖目录
export HIVE_AUX_JARS_PATH=/home/czq/hive/apache-hive-3.1.1-bin/lib

hive-site.xml

配置hive-site.xml需要特别注意的是javax.jdo.option.ConnectionDriverName
老版本填com.mysql.jdbc.Driver
现在应该填com.mysql.cj.jdbc.Driver
不然会报错

<?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>
  <!-- WARNING!!! This file is auto generated for documentation purposes ONLY! -->
  <!-- WARNING!!! Any changes you make to this file will be ignored by Hive.   -->
  <!-- WARNING!!! You must make your changes in hive-site.xml instead.         -->
  <!-- Hive Execution Parameters -->
    <property>
    	<!--数据库用户名-->
        <name>javax.jdo.option.ConnectionUserName</name>
        <value>hive</value>
    </property>
    <property>
    <!--密码-->
        <name>javax.jdo.option.ConnectionPassword</name>
        <value>123456</value>
    </property>
   <property>
   <!--数据库URL-->
        <name>javax.jdo.option.ConnectionURL</name>mysql
        <value>jdbc:mysql://AliCloud:3306/hive_db?useSSL=false</value>
    </property>
    <property>
    <!--数据库连接驱动名-->
        <name>javax.jdo.option.ConnectionDriverName</name>
        <value>com.mysql.cj.jdbc.Driver</value>
    </property>
</configuration>

复制JDBC驱动包

去官网载一个jdbc的驱动包,放到hive的lib文件夹下
Hive 3.1.1安装与配置
在MySQL Connetors下选择Connector/J,进入jdbc下载页面。
选择Platform Independent,下载第一个后缀为tar的包。
解压后是这样的
Hive 3.1.1安装与配置
将mysql-connector-java.8.0.15.jar复制到hive的lib里面去就行了。

删除slf4j-log4j

为什么要这一步呢?当然是因为会报错。在初始化或是进hive都会报错。
hadoop的comment/lib下有个slf4j-log4j。
hive的lib下也有一个slf4j-log4j。
当你配置完环境变量后,hive就会找到两个这样的文件,于是他就不知道用那个了。然后便报错。
网上查了一下解决方案,很简单,删掉一个。
不过,需要注意的是,你只可以删hive的slf4j-log4j!
因为删了hadoop的slf4j-log4j在你start-dfs.sh的时候会报错!
别问我为什么知道。
多么痛的领悟。

在mysql数据库中添加用户,建立数据库

这一部分就不赘述了。
需要注意的是:
1.用户名,密码,数据库名都要和hive-site.xml里面配置的一样
2.一定要给用户足够的权限,让其操作数据库。

初始化

这一步特别简单,只要执行下面代码就行了。
只要前面没有出错,这一步就不会有问题。
不然能让人头皮发麻

schematool -dbType mysql -initSchema

初始化结束后在数据库中多了很多表,用于存放hive的元数据,感兴趣可以看看。
在hdfs上也多出一些文件夹/usr/hive/warehouse

开启hive

hive就完事了。

hive