Hive常用交互命令&属性配置

一、Hive常用交互命令

1. 使用hive –help命令查看有哪些交互命令

which: no hbase in (/usr/java/jdk1.8/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/opt/module/hive/apache-hive-2.1.0-bin/bin:/opt/module/hadoop/hadoop-2.6.4/bin:/root/bin)SLF4J: Class path contains multiple SLF4J bindings.SLF4J: Found binding in [jar:file:/opt/module/hive/apache-hive-2.1.0-bin/lib/hive-jdbc-2.1.0-standalone.jar!/org/slf4j/impl/StaticLoggerBinder.class]SLF4J: Found binding in [jar:file:/opt/module/hadoop/hadoop-2.6.4/share/hadoop/common/lib/slf4j-log4j12-1.7.5.jar!/org/slf4j/impl/StaticLoggerBinder.class]SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.SLF4J: Actual binding is of type [org.apache.logging.slf4j.Log4jLoggerFactory]
报这些提示信息:是因为我还没安装hbase和SLF4J的jar包冲突,Hbase后续我会完善大数据环境
SLF4J解决办法:这是jar包冲突了,删除hive中$HIVE_HOME/lib下面的log4j-slf4j-impl-2.4.1.jar包即可。千万不要删除hadoop下面的,否则调用shell 脚本start-all.sh远程启动hadoop时会报找不到log4j包的错误。
如果报这个提示信息:Fri May 08 11:26:01 CST 2020 WARN: Establishing SSL connection without server's identity verification is not recommended. According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn't set. For compliance with existing applications not using SSL the verifyServerCertificate property is set to 'false'. You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server certificate verification.
解决办法:修改hive-site.xml,将连接URL的value设置成如下所示
<property>    
<name>javax.jdo.option.ConnectionURL</name>    
<!--
<value>jdbc:derby:;databaseName=metastore_db;create=true</value>
-->    
<value>jdbc:mysql://localhost:3306/hive?createDatabaseIfNotExist=true&amp;useSSL=false</value>    
<description>JDBC connect string for a JDBC metastore.To use SSL to encrypt/authenticate the connection, provide database-specific SSL flag in the connection URL.For example, jdbc:postgresql://myhost/db?ssl=true for postgres database.</description>
</property>

2. 解读:”-e” 不进入hive的交互窗口执行sql语句

hive -e 'select * from default.student'

3. “-f”执行脚本中 sql 语句

(1)在/opt/data目录下创建 1.sql 文件

touch 1.sql

文件中写入正确的 sql 语句

select *from default.student;

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

hive -f /opt/data/1.sql

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

hive -f /opt/data/1.sql > /opt/data/hive_result.txt

二、 其他命令

1. 退出 hive 窗口:

hive(default)>exit;

hive(default)>quit; 在新版的 hive 中没区别了,在以前的版本是有的:

exit:先隐性提交数据,再退出;

quit:不提交数据,退出;

2. 在 hive cli 命令窗口中如何查看 hdfs 文件系统

hive(default)>dfs -ls /;

3. 在 hive cli 命令窗口中如何查看本地文件系统

hive(default)>! ls /opt/data;

4. 查看在 hive 中输入的所有历史命令

(1)进入到当前用户的根目录/root

(2)查看. hivehistory 文件

cat .hivehistory

三、 Hive 常见属性配置

1.  Hive 数据仓库位置配置

1)Default 数据仓库的最原始位置是在 hdfs 上的:/user/hive/warehouse 路径下。

2)在仓库目录下,没有对默认的数据库 default 创建文件夹。如果某张表属于 default

数据库,直接在数据仓库目录下创建一个文件夹。

3)修改 default 数据仓库原始位置(将 hive-default.xml.template 如下配置信息拷贝到hive-site.xml 文件中)。

<property>

<name>hive.metastore.warehouse.dir</name>

<value>/user/hive/warehouse</value>

<description>location of default database for the warehouse</description>

</property>

配置同组用户有执行权限:

hdfs dfs -chmod g+w /user/hive/warehouse

2. 查询后信息显示配置

1)在 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)重新启动 hive,对比配置前后差异。

(1)配置前,如图所示

  

(2)配置后,如图所示

3. Hive 运行日志信息配置

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

2.修改 hive 的 log 存放日志到/opt/module/hive/logs

(1)修改hive-log4j.properties.template 文件名称为hive-log4j.properties

[root@node4 conf]# pwd

/opt/module/hive/apache-hive-2.1.0-bin/conf

[root@node4 conf]# cp hive-log4j.properties.template hive-log4j.properties

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

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

 4.  参数配置方式

1.查看当前所有的配置信息

hive>set; (会有很多)

2.参数的配置三种方式

(1)配置文件方式

默认配置文件:hive-default.xml

用户自定义配置文件:hive-site.xml

注意:用户自定义配置会覆盖默认配置。另外,Hive 也会读入 Hadoop 的配置,因为 Hive 是作为 Hadoop 的客户端启动的,Hive 的配置会覆盖 Hadoop 的配置。配置文件的设定对本机启动的所有 Hive 进程都有效。

(2)命令行参数方式

启动 Hive 时,可以在命令行添加-hiveconf param=value 来设定参数。

例如:

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 相关的设定,必须用前两种方式设定,因为那些参数的读取在会话建立以前已经完成了。

  • 1
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

AllenGd

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值