Hive安装及配置
下载hive安装包
此处以hive-0.13.1-cdh5.3.6版本的为例,包名为:hive-0.13.1-cdh5.3.6.tar.gz
解压Hive到安装目录
$ tar -xvf hive-0.13.1-cdh5.3.6.tar.gz
重命名配置文件
mv hive-default.xml.template hive-site.xml
mv hive-env.sh.template hive-env.sh
mv hive-log4j.properties.template hive-log4j.properties
hive-env.sh文件
JAVA_HOME=/usr/local/src/jdk1.8.0_121
HADOOP_HOME=/usr/local/src/hadoop-2.5.0-cdh5.3.6
export HIVE_CONF_DIR=/usr/local/src/hive-0.13.1-cdh5.3.6/conf
hive-site.xml文件
javax.jdo.option.ConnectionURL
jdbc:mysql://master:3306/metastore?createDatabaseIfNotExist=true
JDBC connect string for a JDBC metastore
javax.jdo.option.ConnectionDriverName
com.mysql.jdbc.Driver
Driver class name for a JDBC metastore
javax.jdo.option.ConnectionUserName
root
username to use against metastore database
javax.jdo.option.ConnectionPassword
123456
password to use against metastore database
hive.cli.print.header
true
Whether to print the names of the columns in query output.
hive.cli.print.current.db
true
Whether to include the current database in the Hive prompt.
hive.fetch.task.conversion
more
Some select queries can be converted to single FETCH task minimizing latency.
Currently the query should be single sourced not having any subquery and should not have
any aggregations or distincts (which incurs RS), lateral views and joins.
1. minimal : SELECT STAR, FILTER on partition columns, LIMIT only
2. more : SELECT, FILTER, LIMIT only (TABLESAMPLE, virtual columns)
注意:该版本中hive-site.xml文件在2787h行附近缺少了标签
hive-log4j.properties
hive.log.dir=/usr/local/src/hive-0.13.1-cdh5.3.6/logs
安装Mysql
su - root
yum -y install mysql mysql-server mysql-devel
wget http://dev.mysql.com/get/mysql-community-release-el7-5.noarch.rpm
rpm -ivh mysql-community-release-el7-5.noarch.rpm
yum -y install mysql-community-server
配置Mysql
开启Mysql服务
systemctl start mysqld.service
设置root用户密码
mysqladmin -uroot password '123456'
为用户以及其他机器节点授权
mysql grant all on . to root@'master' identified by '123456';
grant:授权
all:所有权限
.:数据库名称.表名称
root:操作mysql的用户
@'':主机名
密码:123456
完成之后刷新:flush privileges;
拷贝数据库驱动包到Hive根目录下的lib文件夹
cp -a mysql-connector-java-5.1.27-bin.jar /usr/local/src/hive-0.13.1-cdh5.3.6/lib/
启动Hive
bin/hive
修改HDFS系统中关于Hive的一些目录权限
/usr/local/src/hadoop-2.7.2/bin/hadoop fs -chmod 777 /tmp/
/usr/local/src/hadoop-2.7.2/bin/hadoop fs -chmod 777 /user/hive/warehouse
创建数据库
create database school;
创建表操作
create table t1(eid int, name string, sex string) row format delimited fields terminated by '\t';
导入数据到hive表
从本地导入:
load data local inpath '文件路径' into table 库名.表名;(此步骤已经将文件上传到HDFS了)
从HDFS系统导入
Hive历史命令存放地
cat ~/.hivehistory
主要用于排查逻辑错误或者查看常用命令
Hive临时生效设置
固定语法:set 属性名=属性值
例如:set hive.cli.print.header=false;