hive
# 如果使用derby SQL数据库,会在当前工作目录下生成一个metastore_db目录,这个目录是启动Hive会话时由Derby创建的。
<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="configuration.xsl"?>
<configuration>
<property>
<name>hive.metastore.warehouse.dir</name>
<value>/home/me/hive/warehouse</value>
<description>
设置本地warehouse的位置
Local or HDFS directory where Hive keeps table contents.
</description>
</property>
<property>
<name>hive.metastore.local</name>
<value>true</value>
<description>
使用本地模式
Use false if a production metastore server is used.
</description>
</property>
# 设置derby的metastore_db的固定位置,这样可以解决每次启动hive会话时创建一个新的metastore
<property>
<name>javax.jdo.option.ConnectionURL</name>
<value>jdbc:derby:;databaseName=/home/me/hive/metastore_db;create=true</value>
<description>
The JDBC connection URL.
</description>
</property>
</configuration>
<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="configuration.xsl"?>
<configuration>
<property>
<name>javax.jdo.option.ConnectionURL</name>
<value>jdbc:mysql://db1.mydomain.pvt/hive_db?createDatabaseIfNotExist=true</value>
</property>
<property>
<name>javax.jdo.option.ConnectionDriverName</name>
<value>com.mysql.jdbc.Driver</value>
</property>
<property>
<name>javax.jdo.option.ConnectionUserName</name>
<value>database_user</value>
</property>
<property>
<name>javax.jdo.option.ConnectionPassword</name>
<value>database_pass</value>
</property>
</configuration>
# 查看cli选项
hive --h--service cli
# 变量和属性
--define key=value实际上和--hivevar key=value是等价的。二者都可以让用户在命令行定义用户自定义变量以便在Hive脚本中引用,来满足不同情况的执行
# 在hive-shell中使用
set evn:HOME;
# 打印hivevar,hiveconf,system和env中的变量
set;
# 还会打印Hadoop中所定义的所有属性
set -v;
# 定义变量
hive --define foo=bar
hive --hivevar foo=bar4;
# 查看foo变量
set hivevar:foo;
# 修改变量
set hivevar:foo=bar2;
# 使用变量${hivevar:foo}或${foo}
create table toss1(i int,${hivevar:foo} string);
create table toss2(i int,${foo} string);
# 使用hiveconf
hive --hiveconf hive.cli.print.current.db=true
# 查看属性
set hive.cli.print.current.db;
# 修改属性
set hiveconf:hive.cli.print.current.db=false;
set hive.cli.print.current.db=false;
# hive v0.8.0支持新增属性
hive --hiveconf y=5;
# 获取hiveconf值
${hiveconf:y}
# 查看user.name
set system:user.name;
# 设置user.name
set system:user.name=yourusername;
# -e执行sql
hive -e "select * from mytable limit 3";
# 静默模式,去掉OK和其他无关输出信息
hive -S "select * from mytable limit 3" > /tmp/myquery
# 模糊查询相关属性
hive -S -e "set"|grep warehouse
# hive在启动时会首先home目录下寻找名为.hiverc的文件
hive -i
# 在Home目录下编写.hiverc文件
ADD JAR /path/test.jar
set hive.cli.print.current.db=true;
! /bin/echo "what up dog";
dfs -ls -R /;
## 显示字段名称
set hive.cli.print.header=true;