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)>