安装:

位置:

尚硅谷大数据技术之Hive(V3.1).docx
第二章

常改属性:

Hive运行日志信息配置

1)Hive的log默认存放在/tmp/atguigu/hive.log目录下(当前用户名下)

2)修改hive的log存放日志到/opt/module/hive/logs
(1)修改$HIVE_HOME/conf/hive-log4j.properties.template文件名称为
hive-log4j.properties

  1. [atguigu@hadoop102 conf]$ pwd
  2. /opt/module/hive/conf
  3. [atguigu@hadoop102 conf]$ mv hive-log4j.properties.template hive-log4j.properties

(2)在hive-log4j.properties文件中修改log存放位置

  1. property.hive.log.dir=/opt/module/hive/logs

Hive启动jvm堆内存设置

新版本的hive启动的时候,默认申请的jvm堆内存大小为256M,jvm堆内存申请的太小,导致后期开启本地模式,执行复杂的sql时经常会报错:java.lang.OutOfMemoryError: Java heap space,因此最好提前调整一下HADOOP_HEAPSIZE这个参数

(1)修改$HIVE_HOME/conf下的hive-env.sh.template为hive-env.sh

  1. [atguigu@hadoop102 conf]$ pwd
  2. /opt/module/hive/conf
  3. [atguigu@hadoop102 conf]$ cp hive-env.sh.template hive-env.sh

(2)将hive-env.sh其中的参数 export HADOOP_HEAPSIZE=1024的注释放开,重启hive。
image.png

启动服务

  1. hive cli : 命令行<br /> hiveserver2: 允许使用JDBC方式连接hive<br /> hiveserver2提供了:beeline(jdbc客户端),需要先启动hiveserver2,以提供10000端口号<br /> hivemetastore service 读写元数据、

区别:
hive cli 和 hiveserver2 功能: 解析HQL ———> 读写元数据————->翻译为Job提交允许
hivemetastore service : 提供元数据的操作服务

启动脚本:

hiveservices.sh

常用命令:

1)“-e”不进入hive的交互窗口执行sql语句

  1. [atguigu@hadoop102 hive]$ bin/hive -e "select id from default.student;"

2)“-f”执行脚本中sql语句
(1)在/opt/module/hive/下创建datas目录并在datas目录下创建hivef.sql文件

  1. [atguigu@hadoop102 datas]$ vim hivef.sql

(2)文件中写入正确的sql语句

  1. select * from default.student;

(3)执行文件中的sql语句

  1. [atguigu@hadoop102 hive]$ bin/hive -f /opt/module/hive/datas/hivef.sql

(4)执行文件中的sql语句并将结果写入文件中

  1. [atguigu@hadoop102 hive]$ bin/hive -f /opt/module/hive/datas/hivef.sql > /opt/module/datas/hive_result.txt