1 hive的交互命令
hive 作为一个可执行脚本,一同提供了8个可选择的参数,其中
hive -help
可显示其他7个脚本的用法。
usage: hive
-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 -e 不进入 hive 的交互窗口执行 sql 语句会在终端上显示mapreduce的进度,执行完毕后,最后把查询结果输出到终端上。
hive -e "use db_hive;select * from student;"
-
**hive -S ** 使用静音模式执行一个查询,加入-S,终端上的输出不会有mapreduce的进度,执行完毕,只会把查询结果输出到终端上。
hive -S -e "use db_hive;select * from student;"
-
hive -e 执行脚本中 sql 语句
(1)创建一个文件,并写入一条SQL
vi hive_test.sql
#写入
use db_hive;
select * from student;
-
hive -d 设置变量
定义一个变量值,这个变量可以在Hive交互Shell中引用
#设置 变量k1 hive -d k1=v1 –database db_hive #在db_hive数据库中使用该变量 select ‘${k1}’
-
hive --hivevar <key=value> 用法和 hive -d 一样
-
hive --hiveconf <property=value>;
可以使用该选项设定Hive的运行参数配置。
#设置reduce的数量 /hive –hiveconf mapred.reduce.tasks=20
-
hive -i filename
在执行hive前,可以把配置信息,和定义的信息的写人文件中,在用 -i 去读取文件中的信息;
5.2 hive的其他命令操作
-
退出hive的cli
quit ;和 exit;
-
set 设置hive的运行配置参数
#设置reduce的数量 set mapred.reduce.tasks=20;
-
reset 重置hive运行配置参数
将设置过配置参数还原到与hive-site.xml中的一样。
-
set --v 查看hive的运行参数
-
! <command>
在hive中使用linux的命令
-
dfs
在hive中执行hdfs的命令
-
查看hive 的所有的历史命令
(1)进入到当前用户的根目录 /root 或/home/atguigu
(2)查看. hivehistory 文件cat .hivehistory