day55-Hive

day55-Hive

Hive

通过Hive去访问数据库

直接通过hive命令就能够访问数据库
退出使用quit;

打印当前库和表头

修改配置文件hive-site.xml

<!--打印当前的库-->
<property>
    <name>hive.cli.print.current.db</name>
    <value>true</value>
</property>
<!--打印表头-->
<property>
    <name>hive.cli.print.header</name>
    <value>true</value>
</property>

Hive 常用交互命令

  • hive -help 查看帮助文档
查看帮助文档:
 -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)
  • 不进入hive的交互窗口执行sql语句 -e
hive -e "select id from default.mytab;"
  • 执行脚本中sql语句 -f
hive -f file.sql

Hive其他命令操作

  • 退出hive窗口
exit;
quit;
  • hive cli命令窗口查看hdfs文件系统
dfs -ls / ;
  • hive中输入的所有历史命令
进入当前用户的根目录/root或home/atguigu
查看.hivehistory文件

Hive常见属性配置

Hive运行日志信息配置

通过修改 /opt/module/hive-3.1.2/conf 里 hive-log4j2.properties 文件,修改日志保存路径
	1. 更改文件的名字hive-log4j2.properties.template 为 hive-log4j2.properties,否则配置不生效
	2. 修改配置:
		property.hive.log.dir = /路径

参数配置方式

  • 查看当前的所有的配置信息
进入hive的客户端
	set;
查看某个参数的设置:
	set mapred.reduce.tasks;
  • 参数配置的三种方式
1. 配置文件方式
	默认配置文件:hive.default.xml.template 
	自定义配置:hive-site.xml
	注意:用户自定义配置会覆盖默认配置。另外,Hive也会读入Hadoop的配置,因为Hive是作为Hadoop的客户端启动的,Hive的配置会覆盖Hadoop的配置。配置文件的设定对本机启动的所有Hive进程都有效。
2. 命令行参数方式
	启动Hive时,可以在命令行添加-hiveconf param=value来设定参数
	例如:hive -hiveconf mapred.reduce.tasks=10;
	注意:仅对本次hive启动有效
3. 参数声明方式
	可以在HQL中使用set关键字设定参数
	例如: set mapred.reduce.tasks=100;
	注意:仅对本次hive启动有效。
上述三种设定方式的优先级依次递增。
注意:某些系统级的参数:例如log4j相关的设定,必须用前两种方式设定,因为那些参数的读取在会话
posted @ 2022-05-14 21:40  黎白昼  阅读(30)  评论(0)    收藏  举报