一、前提:
安装hive所需要的虚拟机环境为虚拟机安装有Hadoop并且集群成功,同时Hadoop需要在启动状态下,同时需要安装有mysql。不需要有zookeeper和HA,由于HA中含有大量进程,启动会占用很多资源,建议不要有HA
二、安装步骤:
1、上传jar包至/usr/local/soft
将hive-3.1.2上传到虚拟机中的/usr/local/soft目录下
2、解压并重命名
3、配置环境变量
三、配置HIVE文件
1、配置hive-env.sh
2、配置hive-site.xml
上传hive-site.xml到conf目录:
hive-site.xml文件内容:
<configuration>
<property>
<!-- 查询数据时 显示出列的名字 -->
<name>hive.cli.print.header</name>
<value>true</value>
</property>
<property>
<!-- 在命令行中显示当前所使用的数据库 -->
<name>hive.cli.print.current.db</name>
<value>true</value>
</property>
<property>
<!-- 默认数据仓库存储的位置,该位置为HDFS上的路径 -->
<name>hive.metastore.warehouse.dir</name>
<value>/user/hive/warehouse</value>
</property>
<!-- 8.x -->
<property>
<name>javax.jdo.option.ConnectionURL</name>
<value>jdbc:mysql://localhost:3306/hive?createDatabaseIfNotExist=true&useSSL=false&serverTimezone=GMT</value>
</property>
<!-- 8.x -->
<property>
<name>javax.jdo.option.ConnectionDriverName</name>
<value>com.mysql.jdbc.Driver</value>
</property>
<property>
<name>javax.jdo.option.ConnectionUserName</name>
<value>root</value>
</property>
<property>
<name>javax.jdo.option.ConnectionPassword</name>
<value>123456</value>
</property>
<!-- hiveserver2服务的端口号以及绑定的主机名 -->
<property>
<name>hive.server2.thrift.port</name>
<value>10000</value>
</property>
<property>
<name>hive.server2.thrift.bind.host</name>
<value>master</value>
</property>
</configuration>
3、配置日志
4、修改默认配置文件
5、上传MySQL连接jar包
四、修改MySQL编码
修改mysql编码为UTF-8:
1、 编辑配置文件
vim /etc/my.cnf
2、加入以下内容:
[client]
default-character-set = utf8mb4
[mysqld]
character-set-server = utf8mb4
collation-server = utf8mb4_general_ci
3、 重启mysql
systemctl restart mysqld
五、初始化HIVE
六、进入hive
七、后续配置
修改mysql元数据库hive,让其hive支持utf-8编码以支持中文
登录mysql:
mysql -u root -p123456
切换到hive数据库:
use hive;
1).修改字段注释字符集
alter table COLUMNS_V2 modify column COMMENT varchar(256) character set utf8;
2).修改表注释字符集
alter table TABLE_PARAMS modify column PARAM_VALUE varchar(4000) character set utf8;
3).修改分区表参数,以支持分区键能够用中文表示
alter table PARTITION_PARAMS modify column PARAM_VALUE varchar(4000) character set utf8;
alter table PARTITION_KEYS modify column PKEY_COMMENT varchar(4000) character set utf8;
4).修改索引注解(可选)
alter table INDEX_PARAMS modify column PARAM_VALUE varchar(4000) character set utf8;
5).修改库注释字符集
alter table DBS modify column DESC varchar(4000) character set utf8;
八、测试hive
1、启动hive
2、在hive中创建test1数据库
create database test1;
3、切换test1数据库:
use test1;
4、创建students表:
create table students(
id bigint comment '学生id',
name string comment '学生姓名',
age int comment '学生年龄',
gender string comment '学生性别',
clazz string comment '学生班级'
) comment '学生信息表'
ROW FORMAT DELIMITED FIELDS TERMINATED BY ',';
5、创建score表:
create table score(
id bigint comment '学生id',
score_id bigint comment '科目id',
score int comment '学生成绩'
) comment '学生成绩表'
ROW FORMAT DELIMITED FIELDS TERMINATED BY ',';
6、查看表信息:
desc students;
desc score;
九、配置JDBC连接
Hadoop 中的core-site.xml添加如下:
<property>
<name>hadoop.proxyuser.root.hosts</name>
<value>*</value>
</property>
<property>
<name>hadoop.proxyuser.root.groups</name>
<value>*</value>
</property>
启动hiveserver2
hive --service hiveserver2