1. 安装mysql数据库(这个可以用其他DB代替),安装方法参照以前写的Mysql安装教程。
- 登录mysql,创建hive用户。
```
create user 'hive' identified by 'hive';
grant all privileges on *.* to 'hive'@'%' with grant option;
flush privileges;
```
- 创建hive数据库
```
create database hive;
show databases;
```
-
安装Hadoop集群环境,按照hadoop伪分布式安装教程安装
-
下载Hive安装包,并解压至相关目录
-
设置环境变量
```
#hive pro
export HIVE_HOME=/home/dzy/runsofts/apache-hive-1.2.1
export PATH=$PATH:$HIVE_HOME/bin
export CLASSPATH=$CLASSPATH:$HIVE_HOME/bin
```
使其生效
```source /etc/profile```
-
创建一个IO的tmp文件,笔者在用户根目录下创建的 hive/iotmp 用来修改配置
-
修改Hive配置,将其conf文件中的hive-default.xml.templete配置文件复制改名hive-site.xml,主要修改以下参数
```
<property>
<name>javax.jdo.option.ConnectionURL</name>
<value>jdbc:mysql://localhost:3306/hive</value>
<description>JDBC connect string for a JDBC metastore</description>
</property>
<property>
<name>javax.jdo.option.ConnectionDriverName</name>
<value>com.mysql.jdbc.Driver</value>
<description>Driver class name for a JDBC metastore</description>
</property>
<property>
<name>javax.jdo.option.ConnectionUserName</name>
<value>hive</value>
<description>Username to use against metastore database</description>
</property>
<property>
<name>javax.jdo.option.ConnectionPassword</name>
<value>hive</value>
<description>password to use against metastore database</description>
</property>
<property>
<name>hive.querylog.location</name>
<value>/home/dzy/logs/hive_logs</value>
<description>Location of Hive run time structured log file</description>
</property>
<property>
<name>hive.exec.local.scratchdir</name>
<value>/home/dzy/hive/iotmp/hive-${user.name}</value>
<description>Local scratch space for Hive jobs</description>
</property>
<property>
<name>hive.downloaded.resources.dir</name>
<value>/home/dzy/hive/iotmp</value>
<description>Temporary local directory for added resources in the remote file system.</description>
</property>
```
- 启动hive,如果出现以下提示,需要将conf中的复制修改
cp hive-env.sh.template hive-env.sh
```
dzy@dzy-pc ~/runsofts/apache-hive-1.2.1/conf $ hive
Cannot find hadoop installation: $HADOOP_HOME or $HADOOP_PREFIX must be set or hadoop must be in the path
```
将其中的修改
```
# Set HADOOP_HOME to point to a specific hadoop install directory
HADOOP_HOME=/home/dzy/runsofts/hadoop
```
-
启动hive,此时正常启动。此时mysql的hive库中多了很多表。
-
在启动的hive中直接创建表
```
hive> create table test1(name string,age int);
OK
Time taken: 0.793 seconds
hive> show tables;
OK
test1
Time taken: 0.046 seconds, Fetched: 1 row(s)
hive> desc te
temporary terminated textfile
hive> desc test1;
OK
name string
age int
Time taken: 0.185 seconds, Fetched: 2 row(s)
```
- 在mysql查看创建的表,这个表不是物理表哦~
```
select * from hive.TBLS
```
- 删除该表
drop table test1