Hive 配置

本文详细介绍了Hive 1.2.1版本的配置过程,包括hive-env.sh、hive-site.xml和hive-log4j.properties的设置方法,以及如何通过配置文件、命令行参数和HQL中的SET关键字进行参数设定。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

我使用的hive版本是1.2.1,以下是默认的配置文件。

hive-env.sh

重命名hive-env.sh.templatehive-env.sh,修改如下信息:

# Set HADOOP_HOME to point to a specific hadoop install directory
# 设置Hadoop安装目录
export HADOOP_HOME=/opt/module/hadoop-2.7.2

# Hive Configuration Directory can be controlled by:
# Hive配置文件目录
export HIVE_CONF_DIR=/opt/module/hive-1.2.1/conf

hive-site.xml

默认情况下,没有hive-site.xml这个文件,我们可以自己创建一个或者拷贝一份hive-default.xml.template,我是新创建的。

<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="configuration.xsl"?>
<configuration>
    <property>
        <name>javax.jdo.option.ConnectionURL</name>
        <value>jdbc:mysql://hadoop101:3306/metastore?createDatabaseIfNotExist=true</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>root</value>
        <description>username to use against metastore database</description>
    </property>
    <property>
        <name>javax.jdo.option.ConnectionPassword</name>
        <value>asd123</value>
        <description>password to use against metastore database</description>
    </property>
    <property>
        <name>hive.cli.print.current.db</name>
        <value>true</value>
        <description>是否显示当前的数据库</description>
    </property>
    <property>
        <name>hive.cli.print.header</name>
        <value>true</value>
        <description>是否显示表字段</description>
    </property>
    <property>
        <name>hive.metastore.warehouse.dir</name>
        <value>/user/hive/warehouse</value>
        <description>Hive数据仓库位置配置</description>
    </property>
</configuration>

hive-log4j.properties

Hive的log默认存放在/tmp/root/hive.log目录下(当前用户名下),修改/opt/module/hive/conf/hive-log4j.properties.template文件名称为hive-log4j.properties

# Define some default values that can be overridden by system properties
hive.log.threshold=ALL
hive.root.logger=INFO,DRFA
hive.log.dir=/opt/module/hive-1.2.1/logs   ##修改此处
hive.log.file=hive.log

# Define the root logger to the system property "hadoop.root.logger".
log4j.rootLogger=${hive.root.logger}, EventCounter

# Logging Threshold
log4j.threshold=${hive.log.threshold}

参数配置方式

配置文件方式

默认配置文件:hive-default.xml
用户自定义配置文件:hive-site.xml

注意:用户自定义配置会覆盖默认配置。另外,Hive也会读入Hadoop的配置,因为Hive是作为Hadoop的客户端启动的,Hive的配置会覆盖Hadoop的配置。配置文件的设定对本机启动的所有Hive进程都有效。

命令行参数方式

启动Hive时,可以在命令行添加-hiveconf param=value来设定参数,仅对本次hive启动有效

#设置 不显示当前数据库
hive -hiveconf hive.cli.print.current.db=false
#设置 显示当前数据库名字
hive -hiveconf hive.cli.print.current.db=true

参数声明方式

可以在HQL中使用SET关键字设定参数,仅对本次hive启动有效

[root@hadoop101 conf]# hive

Logging initialized using configuration in file:/opt/module/hive-1.2.1/conf/hive-log4j.properties
hive (default)> set hive.cli.print.current.db=false;
hive> set hive.cli.print.current.db=true;
hive (default)> 

查看参数设置
hive (default)> set hive.cli.print.current.db;
hive.cli.print.current.db=true
hive (default)> 

上述设定方式的优先级依次递增。即配置文件<命令行参数<参数声明。注意某些系统级的参数,例如log4j相关的设定,必须用前两种方式设定,因为那些参数的读取在会话建立以前已经完成了。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值