Hive搭建

我们的版本约定

	JAVA_HOME=/usr/local/soft/jdk1.8.0_171
	HADOOP_HOME=/usr/local/soft/hadoop-2.7.6
	HIVE_HOME=/usr/local/soft/hive-1.2.1

安装Hive

#前提是:mysql和hadoop必须已经成功启动了

//查看MySQL是否成功启动
systemctl status mysqld
//查看hadoop是否成功启动
jps

1、在MySQL中创建hive元数据库

mysql -uroot -p123456

create database hive character set "latin1";

2、上传并解压 hive 的安装包

//切换目录
cd /usr/local/module/

//解压
tar -zxvf apache-hive-1.2.1-bin.tar.gz -C /usr/local/soft/

//重命名
cd /usr/local/soft
mv apache-hive-1.2.1-bin hive-1.2.1

#hive的目录信息

3、配置环境变量

vim /etc/profile

HIVE_HOME=/usr/local/soft/hive-1.2.1
export PATH=$HIVE_HOME/bin:$PATH

source /etc/profile

4、修改配置文件

cd /usr/local/soft/hive-1.2.1/conf

cp hive-env.sh.template hive-env.sh
cp hive-default.xml.template hive-site.xml

//修改hive-env.sh
vim hive-env.sh
//添加
HADOOP_HOME=/usr/local/soft/hadoop-2.7.6
JAVA_HOME=/usr/local/soft/jdk1.8.0_171
HIVE_HOME=/usr/local/soft/hive-1.2.1

//修改hive-site.xml
vim hive-site.xml
//注意 这边是修改而不是替换
通过 / 来查找 并修改

        <property>
            <name>javax.jdo.option.ConnectionURL</name>
            <value>jdbc:mysql://master:3306/hive?useSSL=false</value>
        </property>
        <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>
        <property>
            <name>hive.querylog.location</name>
            <value>/usr/local/soft/hive-1.2.1/tmp</value>
        </property>
        <property>
            <name>hive.exec.local.scratchdir</name>
            <value>/usr/local/soft/hive-1.2.1/tmp</value>
        </property>
        <property>
            <name>hive.downloaded.resources.dir</name>
            <value>/usr/local/soft/hive-1.2.1/tmp</value>
        </property>
        
//拷贝mysql驱动到$HIVE_HOME/lib目录下
cp /usr/local/module/mysql-connector-java-5.1.49.jar /usr/local/soft/hive-1.2.1/lib/
    
//将hive的 jline-2.12.jar 拷贝到hadoop对应目录下
cp /usr/local/soft/hive-1.2.1/lib/jline-2.12.jar /usr/local/soft/hadoop-2.7.6/share/hadoop/yarn/lib/

5、启动/退出hive

//启动
hive
//退出
exit;

6、修改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;
alter table PARTITIONS modify column PART_NAME varchar(4000) character set utf8 COLLATE utf8_general_ci DEFAULT NULL;
alter table PARTITION_KEY_VALS modify column PART_KEY_VAL varchar(4000) character set utf8 COLLATE utf8_general_ci DEFAULT NULL;

4).修改索引注解(可选)
alter table INDEX_PARAMS modify column PARAM_VALUE varchar(4000) character set utf8;

7、测试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;
posted @ 2022-02-17 23:11  赤兔胭脂小吕布  阅读(51)  评论(0编辑  收藏  举报