一、实验环境
二、下载安装
三、核心文件配置
3.1 hive-site.xml
四、启动程序
------------------------------------------------
一、实验环境
1.1 安装环境:centos7:hadoop用户
1.2 安装mysql:https://www.cnblogs.com/xiaojy2021/p/14948543.html
1.3 在mysql上建立hive数据库:
mysql> create database hive; # 创建数据库
mysql> create user 'hiveowner'@'%' identified by 'Welcome_h1'; # 创建用户
mysql> grant all on hive.* TO 'hiveowner'@'%'; # 给该用户授权
mysql> grant all on hive.* TO 'hiveowner'@'localhost' identified by 'Welcome_h1';
1.4 把MySQL的Driver放到Hive的lib目录:
二、Hive下载安装
2.1 下载地址:https://archive.apache.org/dist/hive/hive-2.3.0/
2.2 进入文件存放目录,解压缩:
$ sudo tar -zxvf apache-hive-2.3.0-bin.tar.gz -C /usr/local/hdfs/
$ cd /usr/local/hdfs/
$ sudo mv ./apache-hive-2.3.0-bin ./hive2.3
2.3 把MySQL的Driver放到Hive的lib目录:sudo cp ./mysql-connector-java-5.1.43-bin.jar /usr/local/hdfs/hive2.3/lib/
$ sudo chown -R hadoop ./hive2.3
$ sudo ln -s /usr/local/hdfs/hive2.3 ~/hdfs/hive
vi ~/.bash_profile
HIVE_HOME=/home/hadoop/hdfs/hive
export HIVE_HOME
PATH=$HIVE_HOME/bin:$PATH
export PATH
source ~/.bash_profile
在任何界面输入hive,然后连续按两下Tab键,显示下面内容则设置成功:
$ hive
hive hive-config.sh hiveserver2 hivexget hivexml hivexregedit hivexsh
三、核心文件配置
3.1 hive-site.xml
$ cd ~/hdfs/hive/conf
$ sudo vi hive-site.xml
$ sudo chown -R hadoop ./hive-site.xml # 因为是hadoop用户登录,记得更改文件归属
粘贴内容
<?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://localhost:3306/hive?useSSL=false</value>
</property>
<property>
<name>javax.jdo.option.ConnectionDriverName</name>
<value>com.mysql.jdbc.Driver</value>
</property>
<property>
<name>javax.jdo.option.ConnectionUserName</name>
<value>hiveowner</value>
</property>
<property>
<name>javax.jdo.option.ConnectionPassword</name>
<value>Welcome_1</value>
</property>
</configuration>
初始化MetaStore:
先登录mysql查看hive下的表:
$ mysql -u hiveowner -p
mysq> use hive;
mysql> show tables;
Empty set (0.00 sec)
mysql> \q;
$ cd ~/hdfs/hive/bin
$ schematool -dbType mysql -initSchema
再进入mysql查看hive.tables,显示下列信息则初始化成功:
mysql> show tables;
+---------------------------+
| Tables_in_hive |
+---------------------------+
| AUX_TABLE |
| BUCKETING_COLS |
| CDS |
| COLUMNS_V2 |
......
四、启动程序
$ start-all.sh
$ hive
输入指令,运行成功
hive> show databases;
OK
default
Time taken: 0.651 seconds, Fetched: 1 row(s)
hive>exit;