我使用的hive版本是1.2.1
,以下是默认的配置文件。
hive-env.sh
重命名hive-env.sh.template
为hive-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相关的设定,必须用前两种方式设定,因为那些参数的读取在会话建立以前已经完成了。