转:http://springsfeng.iteye.com/blog/1734517
1 . 首先请安装好MySQL并修改root账户密码,使用root账户执行下面命令:
su - root
mysql
GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' IDENTIFIED BY 'root' WITH GRANT OPTION;
2. 创建Hive用户: 使用root账户执行下面命令:
su - root
mysql -uroot -p
CREATE USER 'hive'@'localhost' IDENTIFIED BY 'hive';
CREATE USER 'hive'@'linux-fdc.linux.com' IDENTIFIED BY 'hive';
CREATE USER 'hive'@'192.168.81.251' IDENTIFIED BY 'hive';
CREATE DATABASE metastore;
CREATE DATABASE metastore DEFAULT CHARACTER SET latin1 DEFAULT COLLATE latin1_swedish_ci;
GRANT ALL PRIVILEGES ON metastore.* TO 'hive'@'localhost' IDENTIFIED BY 'hive' WITH GRANT OPTION;
GRANT ALL PRIVILEGES ON metastore.* TO 'hive'@'192.168.81.251' IDENTIFIED BY 'hive' WITH GRANT OPTION;
flush privileges;
3. 导入MySQL 脚本
使用hive账户登录:
mysql -uhive -p -h192.168.81.251
mysql> use metastore;
Database changed
mysql> source /opt/custom/hive-0.11.0/scripts/metastore/upgrade/mysql/hive-schema-0.10.0.mysql.sql
4. Hive安装配置
(1) 编译:针对当前Hive-0.11.0-SNAPSHOT版本
下载最新的Hive源码包:hive-trunk.zip, 解压至:/home/kevin/Downloads/hive-trunk,修改:
build.properties, 中:
若需修改其他依赖包的版本,请修改:ivy目录下的libraries.properties文件, 例如修改hbase
的版本:
...
guava-hadoop23.version=11.0.2
hbase.version=0.94.6
jackson.version=1.8.8
...
在当前目录下执行:
ant tar -Dforrest.home=/usr/custom/apache-forrest-0.9
其中,forrest.home参考:http://springsfeng.iteye.com/admin/blogs/1734557中的第一部分,
第3小节。
(2) 解压:从编译后的build下Copy hive-0.11.0-SNAPSHOT.tar.gz至:/usr/custom/并解压。
(3) 配置环境变量:
exprot HIVE_HOME=/usr/custom/hive-0.11.0
exprot PATH=$HIVE_HOME/bin:$PATH
(4) 配置文件:
复制conf目录下的.template生成对应的.xml或.properties文件:
cp hive-default.xml.template hive-site.xml
cp hive-log4j.properties.template hive-log4j.properties
(5) 配置hive-config.sh:
(6) 配置日志hive-log4j.properties:针对0.10.0版本的特别处理。
将org.apache.hadoop.metrics.jvm.EventCounter改成:org.apache.hadoop.log.metrics
.EventCounter , 这样将解决异常:
WARNING: org.apache.hadoop.metrics.jvm.EventCounter is deprecated.
Please use org.apache.hadoop.log.metrics.EventCounter in all the log4j.properties files.
(7) 创建hive-site文件:
(8) 配置MySQL-Connector-Java
下载mysql-connector-java-5.1.22-bin.jar放在/usr/custom/hive-0.11.0/lib目录下,否则执行
show tables; 命令时提示找不到ConnectionDriverName。
5. 启动使用
(1) 启动
进入bin目录下,执行命令:hive
(2) 查看当前库及表
show databases; //默认为:default
show tables;
(3) 创建表示例
这部分为我自己的测试, 测试数据见附件。
CREATE TABLE cite (citing INT, cited INT)
ROW FORMAT DELIMITED
FIELDS TERMINATED BY ','
STORED AS TEXTFILE;
CREATE TABLE cite_count (cited INT, count INT);
INSERT OVERWRITE TABLE cite_count
SELECT cited,COUNT(citing)
FROM cite
GROUP BY cited;
SELECT * FROM cite_count WHERE count > 10 LIMIT 10;
CREATE TABLE age (name STRING, birthday INT)
ROW FORMAT DELIMITED
FIELDS TERMINATED BY '\t'
LINES TERMINATED BY '\n'
STORED AS TEXTFILE;
CREATE TABLE age_out (birthday INT, birthday_count INT)
ROW FORMAT DELIMITED
FIELDS TERMINATED BY '\t'
LINES TERMINATED BY '\n'
STORED AS TEXTFILE;
(4) 查看表结构
desribe cite;
(5) 加载数据
hive> LOAD DATA LOCAL INPATH '/home/kevin/Documents/age.txt' OVERWRITE INTO TABLE age;