学习笔记——Hive的进入和退出以及HiveSql 的运行方式

本文介绍了Hive SQL的基本使用方法,包括如何进入和退出Hive窗口,以及三种执行SQL语句的方式:直接在Hive窗口执行、使用shell脚本执行和通过配置文件执行。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Hive的基本使用

进入hive窗口

输入hive即可进入hive窗口

退出

输入 exit;

HiveSql 的两种运行方式

直接在hive窗口中执行 sql 语句

使用 shell 脚本执行 sql 语句

  • 方法一:hive -e 直接执行sql语句, hive -v -e 的v表示展示log信息
    ​ 适用于当想把sql语句自动化执行时,就可以写成shell 脚本的方式,然后通过调度平台调用shell 脚本即可,是常用的一种方式。
    进入hive,运行后自动退出hive
#!/bin/sh
hive -e -v"
show databases;
";
  • 方法二:hive -f 执行sql脚本(包含sql语句) 适用于执行一下大规模的sql语句,但是相比较 hive -e 的方式,hive -f 不能使用 shell 变量没那么灵活,因此不是很常用。
	hive -f xxx.sql

进入hive,运行后自动退出hive

  • 方法三:hive -i 执行配置参数,但是会进入hive 窗口
(base) [frog005@instance-5e92fphs frog005]$ cat frog3.conf 
use default;
set hive.cli.print.current.db=true; # 
(base) [frog005@instance-5e92fphs frog005]$ hive -i frog3.conf 
which: no hbase in (/home/anaconda3/bin:/home/anaconda3/condabin:/opt/sqoop-1.4.7/bin:/opt/java/jdk1.8.0_191/bin:/usr/local/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/opt/hadoop-2.9.1/bin:/opt/hadoop-2.9.1/sbin:/opt/hive-2.3.3/bin:/usr/bin/python:/home/anaconda3/bin:/home/frog005/.local/bin:/home/frog005/bin)
Logging initialized using configuration in jar:file:/opt/hive-2.3.3/lib/hive-common-2.3.3.jar!/hive-log4j2.properties Async: true
Hive-on-MR is deprecated in Hive 2 and may not be available in the future versions. Consider using a different execution engine (i.e. spark, tez) or using Hive 1.X releases.
hive (default)> 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值