一、Hive常用命令
$ hive -help
usage: hive
-d,--define <key=value> Variable substitution to apply to Hive
commands. e.g. -d A=B or --define A=B
--database <databasename> Specify the database to use
-e <quoted-query-string> SQL from command line
-f <filename> SQL from files
-H,--help Print help information
--hiveconf <property=value> Use value for given property
--hivevar <key=value> Variable substitution to apply to Hive
commands. e.g. --hivevar A=B
-i <filename> Initialization SQL file
-S,--silent Silent mode in interactive shell
-v,--verbose Verbose mode (echo executed SQL to the
console)
- “-e”不进入hive的交互窗口执行sql语句
$ bin/hive -e "select id from student;"
- “-f”执行脚本中sql语句
#创建一个sql脚本
$ touch hivef.sql
#编写sql语句
select *from student;
#执行文件中的sql语句
$ bin/hive -f hivef.sql
# 执行文件中的sql语句并将结果写入文件中
$ bin/hive -f hivef.sql > /opt/module/datas/hive_result.txt
- 在hive cli命令窗口中查看hdfs文件系统:
- 查看在hive中输入的所有历史命令 (进入当前用户的根目录/home/user)
#查看隐藏文件命令 ls -a
cat .hivehistory
二、Hive运行日志配置
- Hive的log默认存放在/tmp/hw/hive.log目录下(当前用户名下)
- 修改hive的log存放日志到/opt/module/hive/logs
#修改/opt/module/hive/conf/hive-log4j2.properties.template文件名称为 hive-log4j2.properties
mv hive-log4j2.properties.template hive-log4j2.properties
# 在hive-log4j2.properties文件中修改log存放位置
hive.log.dir=/opt/module/hive/logs
三、Hive打印当前库 和 表头的配置
<property>
<name>hive.cli.print.header</name>
<value>true</value>
</property>
<property>
<name>hive.cli.print.current.db</name>
<value>true</value>
</property>