Hive install on Ubuntu,并以Mysql作为Metastore

安装配置Hive虽然比较简单,但是网上的资料各种坑,总结下来写下本文作为成功后的记录。

下载与放置

Hive

Hive下载地址

1
2
3
4
5
$ sudo tar xzvf apache-hive-2.1.1-bin.tar.gz -C /usr/local
$ cd /usr/local
$ sudo mv apache-hive-2.1.1-bin/ hive
$ sudo chown hadoop@hadoop -R hive
$

mysql

$ sudo apt-get install mysql-server

mysql Java连接

$ sudo apt-get install libmysql-java
并创建软连接
$ ln -s /usr/share/java/mysql-connector-java.jar $HIVE_HOME/lib/mysql-connector-java.jar

环境变量

~/.profile里添加

1
2
export HIVE_HOME=/usr/local/hive
export PATH=$PATH:$HIVE_HOME/bin

source ~/.profile

建表与连接

初始表格

在mysql里创建数据库,格式同hive-schema-2.1.0.mysql.sql ,这里依据你的版本号来

1
2
3
4
5
$ mysql -u root -p
Enter password:
mysql> CREATE DATABASE metastore;
mysql> USE metastore;
mysql> SOURCE /usr/local/hive/scripts/metastore/upgrade/mysql/hive-schema-2.1.0.mysql.sql;;

创建用户并给予权限

1
2
3
mysql> CREATE USER 'hiveuser'@'%' IDENTIFIED BY 'hivepassword'; 
mysql> GRANT all on *.* to 'hiveuser'@localhost identified by 'hivepassword';
mysql> flush privileges;

hive-site.xml

$HIVE_HOME/conf文件夹创建hive-site.xml文件,配置如下

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
<configuration>
<property>
<name>javax.jdo.option.ConnectionURL</name>
<value>jdbc:mysql://localhost/metastore?createDatabaseIfNotExist=true</value>
<description>metadata is stored in a MySQL server</description>
</property>
<property>
<name>javax.jdo.option.ConnectionDriverName</name>
<value>com.mysql.jdbc.Driver</value>
<description>MySQL JDBC driver class</description>
</property>
<property>
<name>javax.jdo.option.ConnectionUserName</name>
<value>hiveuser</value>
<description>user name for connecting to mysql server</description>
</property>
<property>
<name>javax.jdo.option.ConnectionPassword</name>
<value>hivepassword</value>
<description>password for connecting to mysql server</description>
</property>
</configuration>

OK,启动Hive Shell试试看吧

测试一下,在hive shell里建表
hive> create table saurzcode(id int, name string);

再在mysql里查看

1
2
3
4
5
mysql -u root -p
Enter password:
mysql> use metastore;
mysql> show tables ;
mysql> select * from TBLS;

若可以看见上面在hive里建的表saurzcode,恭喜你大功告成!😆😎🤠