hive04

2.7 Hive 常用交互命令
[atguigu@hadoop102 hive]$ bin/hive -help
usage: hive
-d,--define <key=value> Variable subsitution 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 subsitution 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)
1)“-e”不进入 hive 的交互窗口执行 sql 语句
[atguigu@hadoop102 hive]$ bin/hive -e "select id from student;"
2)“-f”执行脚本中 sql 语句
(1)在/opt/module/hive/下创建 datas 目录并在 datas 目录下创建 hivef.sql 文件
[atguigu@hadoop102 datas]$ touch hivef.sql
(2)文件中写入正确的 sql 语句
select *from student;
(3)执行文件中的 sql 语句
[atguigu@hadoop102 hive]$ bin/hive -f /opt/module/hive/datas/hivef.sql
(4)执行文件中的 sql 语句并将结果写入文件中
[atguigu@hadoop102 hive]$ bin/hive -f /opt/module/hive/datas/hivef.sql >
/opt/module/datas/hive_result.txt
2.8 Hive 其他命令操作
1)退出 hive 窗口:
hive(default)>exit;
hive(default)>quit;
2)在 hive cli 命令窗口中如何查看 hdfs 文件系统
hive(default)>dfs -ls /;
3)查看在 hive 中输入的所有历史命令
(1)进入到当前用户的根目录 /root 或/home/atguigu
(2)查看. hivehistory 文件
[atguig2u@hadoop102 ~]$ cat .hivehistory
2.9 Hive 常见属性配置
2.9.1 Hive 运行日志信息配置
1)Hive 的 log 默认存放在/tmp/atguigu/hive.log 目录下(当前用户名下)
2)修改 hive 的 log 存放日志到/opt/module/hive/logs
(1)修改/opt/module/hive/conf/hive-log4j2.properties.template 文件名称为
hive-log4j2.properties
[atguigu@hadoop102 conf]$ pwd
/opt/module/hive/conf
[atguigu@hadoop102 conf]$ mv hive-log4j2.properties.template hive
log4j2.properties
(2)在 hive-log4j2.properties 文件中修改 log 存放位置
hive.log.dir=/opt/module/hive/logs
2.9.2 打印 当前库 和 表头
在 hive-site.xml 中加入如下两个配置:
<property>
<name>hive.cli.print.header</name>
<value>true</value>
</property>
<property>
<name>hive.cli.print.current.db</name>
<value>true</value>
</property>
2.9.3 参数配置方式
1)查看当前所有的配置信息
hive>set;
2)参数的配置三种方式
(1)配置文件方式
默认配置文件:hive-default.xml
用户自定义配置文件:hive-site.xml
注意:用户自定义配置会覆盖默认配置。另外,Hive 也会读入 Hadoop 的配置,因为 Hive
是作为 Hadoop 的客户端启动的,Hive 的配置会覆盖 Hadoop 的配置。配置文件的设定对本
机启动的所有 Hive 进程都有效。
(2)命令行参数方式
启动 Hive 时,可以在命令行添加-hiveconf param=value 来设定参数。
例如:
[atguigu@hadoop103 hive]$ bin/hive -hiveconf mapred.reduce.tasks=10;
注意:仅对本次 hive 启动有效
查看参数设置:
hive (default)> set mapred.reduce.tasks;
(3)参数声明方式
可以在 HQL 中使用 SET 关键字设定参数
例如:
hive (default)> set mapred.reduce.tasks=100;
注意:仅对本次 hive 启动有效。
查看参数设置
hive (default)> set mapred.reduce.tasks;
上述三种设定方式的优先级依次递增。即配置文件<命令行参数<参数声明。注意某些系
统级的参数,例如 log4j 相关的设定,必须用前两种方式设定,因为那些参数的读取在会话
建立以前已经完成了。
posted @ 2021-10-21 10:25  大雄的脑袋  阅读(40)  评论(0编辑  收藏  举报