Hive安装

这篇博客详细介绍了如何安装Hive,包括从Hive官网下载安装文件,将安装包部署到指定目录,配置环境变量,设置元数据存储在MySQL而非默认的derby,解决初始化时缺少mysql连接jar包的问题,以及最后的命令验证步骤。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

  • 下载二进制安装文件
  • 安装到指定目录
  • 配置环境变量
  • 配置元数据存储位置
  • 初始化hive
  • 命令验证

 

(一) 下载二进制安装文件

到Hive官网找到指定版本的文件进行下载(https://mirrors.tuna.tsinghua.edu.cn/apache/hive/)

此处下载最新发布的安装包

#> wget https://mirrors.tuna.tsinghua.edu.cn/apache/hive/hive-3.1.1/apache-hive-3.1.1-bin.tar.gz

 

(二)安装到指定目录

#> tar -zxvf apache-hive-3.1.1-bin.tar.gz  -C /soft

#> ln -s apache-hive-3.1.1-bin hive

 

(三)配置环境变量

#> vim /etc/environment

HIVE_HOME=/soft/hive

PATH=追加"/soft/hive/bin"

 

(四)配置元数据存储位置

原始数据默认存储在derby,改为mysql

在hive安装目录的conf中创建hive-site.xml添加如下配置

#> vim hive-site.xml
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<?xml-stylesheet type="text/xsl" href="configuration.xsl"?>
<configuration>
    <property>
        <name>javax.jdo.option.ConnectionURL</name>
        <value>jdbc:mysql://ipaddress:port/database?createDatabaseIfNotExist=true</value>
    </property>
    <property>
        <name>javax.jdo.option.ConnectionDriverName</name>
        <value>com.mysql.cj.jdbc.Driver</value>
    </property>
    <property>
        <name>javax.jdo.option.ConnectionUserName</name>
        <value>root</value>
    </property>
    <property>
        <name>javax.jdo.option.ConnectionPassword</name>
        <value>password</value>
    </property>
</configuration>

 

(五)初始化hive

#> schematool -dbType mysql -initSchema

hive初始化有可能会出现找不到连接mysql数据库jar包的错误, 如下:

SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/usr/local/hive/lib/log4j-slf4j-impl-2.10.0.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/usr/local/hadoop/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]
Metastore connection URL:	 jdbc:mysql://127.0.0.1:3306/database?createDatabaseIfNotExist=true
Metastore Connection Driver :	 com.mysql.cj.jdbc.Driver
Metastore connection User:	 root
org.apache.hadoop.hive.metastore.HiveMetaException: Failed to load driver
Underlying cause: java.lang.ClassNotFoundException : com.mysql.cj.jdbc.Driver
Use --verbose for detailed stacktrace.
*** schemaTool failed ***

解决办法:

到mysql(https://dev.mysql.com/downloads/connector/j/)网站找到属于服务器系统的版本,下载到服务器就行安装

找到mysql-connector-java-8.0.16.jar,复制到hive的lib目录下即可

如果系统是Ubuntu server 可用 dpkg -l | grep mysql 找到对应的安装包名称,然后用dpkg -L 安装包名称 找到安装路径

(六)命令验证

#> hive -e "show tables;"

 

成功显示如下:

which: no hbase in (/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/soft/jdk/bin:/soft/hadoop/bin:/soft/hadoop/sbin:/soft/hive/bin)
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/soft/apache-hive-3.1.1-bin/lib/log4j-slf4j-impl-2.10.0.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/soft/hadoop-3.2.0/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 = 5535c2a2-05d2-44f9-9b09-80ce7e95c25a

 

Logging initialized using configuration in jar:file:/soft/apache-hive-3.1.1-bin/lib/hive-common-3.1.1.jar!/hive-log4j2.properties Async: true
Hive Session ID = 593ffa38-c0bb-4d1e-9fca-1b2bca8d8276
OK
Time taken: 1.251 seconds

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值