hive常用的交互命令

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)

  1. hive -e 不进入 hive 的交互窗口执行 sql 语句会在终端上显示mapreduce的进度,执行完毕后,最后把查询结果输出到终端上。
hive -e "use db_hive;select * from student;"
  1. **hive -S ** 使用静音模式执行一个查询,加入-S,终端上的输出不会有mapreduce的进度,执行完毕,只会把查询结果输出到终端上。

    hive -S  -e "use db_hive;select * from student;"
    
  2. hive -e 执行脚本中 sql 语句
    (1)创建一个文件,并写入一条SQL

vi hive_test.sql

#写入
use db_hive;
select * from student;
  1. hive -d 设置变量

    定义一个变量值,这个变量可以在Hive交互Shell中引用

    #设置 变量k1
    hive -d k1=v1 –database db_hive
    #在db_hive数据库中使用该变量
    select${k1}

在这里插入图片描述

  1. hive --hivevar <key=value> 用法和 hive -d 一样

  2. hive --hiveconf <property=value>;

    可以使用该选项设定Hive的运行参数配置。

    #设置reduce的数量
    /hive –hiveconf mapred.reduce.tasks=20
    
  3. hive -i filename

    在执行hive前,可以把配置信息,和定义的信息的写人文件中,在用 -i 去读取文件中的信息;

5.2 hive的其他命令操作

  1. 退出hive的cli

    quit ;和 exit;

  2. set 设置hive的运行配置参数

    #设置reduce的数量
    set mapred.reduce.tasks=20;
    
  3. reset 重置hive运行配置参数

    将设置过配置参数还原到与hive-site.xml中的一样。

  4. set --v 查看hive的运行参数

  5. ! <command>

    在hive中使用linux的命令

在这里插入图片描述

  1. dfs

    在hive中执行hdfs的命令

在这里插入图片描述

  1. 查看hive 的所有的历史命令
    (1)进入到当前用户的根目录 /root 或/home/atguigu
    (2)查看. hivehistory 文件

    cat .hivehistory
    
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值