1.通过cli直接执行

2.hive -e "hql"

如:[root@host ~]# hive -e "use gamedw;show tables"

[root@host ~]# hive -e 'use gamedw;show tables'

3.执行文件
[root@host tmpdata]# cat hive.sql
select * from gamedw.v_cust

[root@host ~]# hive -f /root/tmpdata/hive.sql  

SLF4J: Class path contains multiple SLF4J bindings. SLF4J: Found binding in [jar:file:/root/hive/apache-hive-2.1.1/lib/log4j-slf4j-impl-2.4.1.jar!/org/slf4j/impl/StaticLoggerBinder.class] SLF4J: Found binding in [jar:file:/root/spark/spark-2.2.0-bin-hadoop2.7/jars/slf4j-log4j12-1.7.16.jar!/org/slf4j/impl/StaticLoggerBinder.class] SLF4J: Found binding in [jar:file:/root/hadoop/hadoop-2.7.4/share/hadoop/common/lib/slf4j-log4j12-1.7.10.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]

Logging initialized using configuration in file:/root/hive/apache-hive-2.1.1/conf/hive-log4j2.properties Async: true

OK
tianyongtao     1       50      shenzhen
wangwu  1       85      shenzhen
zhangsan        1       20      shenzhen
liuqin  0       56      shenzhen
wangwu  0       47      shenzhen
liuyang 1       32      shenzhen
Time taken: 5.386 seconds, Fetched: 6 row(s)

[root@host ~]# hive -f /root/tmpdata/hive.sql >/root/tmpdata/hivelog.txt   //结果保存到本地

SLF4J: Class path contains multiple SLF4J bindings. SLF4J: Found binding in [jar:file:/root/hive/apache-hive-2.1.1/lib/log4j-slf4j-impl-2.4.1.jar!/org/slf4j/impl/StaticLoggerBinder.class] SLF4J: Found binding in [jar:file:/root/spark/spark-2.2.0-bin-hadoop2.7/jars/slf4j-log4j12-1.7.16.jar!/org/slf4j/impl/StaticLoggerBinder.class] SLF4J: Found binding in [jar:file:/root/hadoop/hadoop-2.7.4/share/hadoop/common/lib/slf4j-log4j12-1.7.10.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]

Logging initialized using configuration in file:/root/hive/apache-hive-2.1.1/conf/hive-log4j2.properties Async: true

OK

Time taken: 4.75 seconds, Fetched: 6 row(s)
[root@host ~]# cat /root/tmpdata/hivelog.txt
tianyongtao     1       50      shenzhen
wangwu  1       85      shenzhen
zhangsan        1       20      shenzhen
liuqin  0       56      shenzhen
wangwu  0       47      shenzhen
liuyang 1       32      shenzhen

同样

 hive -i  /root/tmpdata/hive.sql  也可以执行hql同时开启cli

hive  -hivevar 传递参数

[root@host ~]# cat /root/tmpdata/hivevar.sql
select * from gamedw.v_cust where sex=${varsex} and age>${varage};

[root@host ~]# hive -hivevar varsex=0 -hivevar varage=20 -f /root/tmpdata/hivevar.sql

SLF4J: Class path contains multiple SLF4J bindings. SLF4J: Found binding in [jar:file:/root/hive/apache-hive-2.1.1/lib/log4j-slf4j-impl-2.4.1.jar!/org/slf4j/impl/StaticLoggerBinder.class]

SLF4J: Found binding in [jar:file:/root/spark/spark-2.2.0-bin-hadoop2.7/jars/slf4j-log4j12-1.7.16.jar!/org/slf4j/impl/StaticLoggerBinder.class]

SLF4J: Found binding in [jar:file:/root/hadoop/hadoop-2.7.4/share/hadoop/common/lib/slf4j-log4j12-1.7.10.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]

Logging initialized using configuration in file:/root/hive/apache-hive-2.1.1/conf/hive-log4j2.properties Async: true

OK
liuqin  0       56      shenzhen
wangwu  0       47      shenzhen
Time taken: 5.839 seconds, Fetched: 2 row(s)

[root@host ~]# hive -e "select * from gamedw.cust">>cust.txt SLF4J: Class path contains multiple SLF4J bindings. SLF4J: Found binding in [jar:file:/root/hive/apache-hive-2.1.1/lib/log4j-slf4j-impl-2.4.1.jar!/org/slf4j/impl/StaticLoggerBinder.class] SLF4J: Found binding in [jar:file:/root/spark/spark-2.2.0-bin-hadoop2.7/jars/slf4j-log4j12-1.7.16.jar!/org/slf4j/impl/StaticLoggerBinder.class] SLF4J: Found binding in [jar:file:/root/hadoop/hadoop-2.7.4/share/hadoop/common/lib/slf4j-log4j12-1.7.10.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]

Logging initialized using configuration in file:/root/hive/apache-hive-2.1.1/conf/hive-log4j2.properties Async: true OK Time taken: 9.204 seconds, Fetched: 19 row(s)

[root@host ~]# cat cust.txt
tianyt_touch100 1       50
wangwu  1       85
zhangsan        1       20
liuqin  0       56
wangwu  0       47
liuyang 1       32
hello   0       100
mahuateng       1       1001
tianyt_touch100 1       50
wangwu  1       85
zhangsan        1       20
liuqin  0       56
wangwu  0       47
xiaomage        NULL    51
nihao   1       5
liuyang 1       32
hello   0       100
mahuateng       1       1001
nihao   1       5

hive命令的执行方式的更多相关文章

  1. hive -help hive命令行执行sql参数

    在shell命令行执行 hive -help 结果如下: -d,--define <key=value> Variable substitution to apply to Hive co ...

  2. hive命令的三种执行方式

    hive命令的3种调用方式 方式1:hive –f  /root/shell/hive-script.sql(适合多语句) hive-script.sql类似于script一样,直接写查询命令就行 不 ...

  3. Linux下的Source命令及脚本的执行方式解析

    Linux Source命令及脚本的执行方式解析 http://blog.csdn.net/wangyangkobe/article/details/6595143 当我修改了/etc/profile ...

  4. Source命令及脚本的执行方式

    [Source命令及脚本的执行方式] source filename 与 sh filename 及./filename执行脚本的区别在那里呢? 1.当shell脚本具有可执行权限时,用sh file ...

  5. shell基础概念, if+命令, shell中引用python, shell脚本的几种执行方式

    说明: 虚拟机中shell_test目录用来练习shell, 其中有个test.log文件用来存放日志 #!/usr/bin/bash      # shell文件开头, 用来指定该文件使用哪个解释器 ...

  6. ansible的两种命令执行方式 : ad-hoc / playbook以及通过setup模块获取系统参数

    一.什么是ad-hoc和playbook  ad-hoc : 如果我们敲入一些命令去快速的完成一些操作,而不需要将这些执行过的命令刻意保存下来,这样的命令就叫做as-hoc命令,这里不做过多赘述. p ...

  7. hive 源码笔记(1):命令行执行的主流程。

    1. 'hive'命令是(默认为hive跟目录)./bin下的一个shell脚本,依次加载 ./bin/hive-config.sh, ./conf/hive-env.sh, 设置与hadoop.sp ...

  8. hadoop笔记之Hive的管理(CLI方式)

    Hive的管理(一) Hive的管理(一) Hive的启动方式 CLI(命令行)方式 Web界面方式 远程服务启动方式 CLI方式 1. 进入命令行方式 直接输入<HIVE_HOME>/b ...

  9. hive 命令行传入参数

    azkban实现任务重跑 我们执行sql的方式是将hql文件上传到服务器本地.然后执行shell命令 hive " -f ./test_scheduler.hql 注:hive -e 是执行 ...

随机推荐

  1. 跟着未名学Office - 高效笔记OneNote

    了解OneNote 2016年12月22日    19:57 OneNote Summary 理解OneNote中的笔记本.分区.页的概念 编写人:未名 感谢秦大: http://www.zloffi ...

  2. [蓝桥杯]ALGO-81.算法训练_动态数组使用

    从键盘读入n个整数,使用动态数组存储所读入的整数,并计算它们的和与平均值分别输出.要求尽可能使用函数实现程序代码.平均值为小数的只保留其整数部分. 样例输入: 样例输出: 样例输入: 样例输出: 题目 ...

  3. 【springboot】之利用shell脚本优雅启动,关闭springboot服务

    springbot开发api接口服务,生产环境中一般都是运行独立的jar,在部署过程中涉及到服务的优雅启动,关闭, springboot官方文档给出的有两种方式, 1.使用http shutdown ...

  4. csv文件操作

    1.python2中: import csv infos = [ ['peter','male'], ['marry','female'], ['johon','male'], ['rose','fe ...

  5. CentOS搭建SVN服务器,并通过Apache HTTP方式访问

    摘要:本文主要讲述了在centos 6.5环境下搭建svn服务器,可通过svn:\\IP方式访问.同时由于部分公司内网端口限制,并不能访问外网的svn服务器,所以特地结合了apache服务器,使得可以 ...

  6. Scrapy学习篇(五)之Spiders

    Spiders Spider类定义了如何爬取某个网站.包括了爬取的动作(例如:是否跟进链接)以及如何从网页的内容中提取结构化数据(爬取item).简而言之,Spider就是你定义爬取的动作及分析某个网 ...

  7. go语言学习--指针数组和数组指针

    数组指针(也称行指针)定义 int (*p)[n];()优先级高,首先说明p是一个指针,指向一个整型的一维数组,这个一维数组的长度是n,也可以说是p的步长.也就是说执行p+1时,p要跨过n个整型数据的 ...

  8. 安装 dubbo

    Dubbo的介绍: 是一个java版的RPC框架,由阿里巴巴开发并使用,结合zookeeper,实现流动计算架构完成资源调度和治理的工作 dubbo管控台可以对注册到zookeeper注册中心的服务或 ...

  9. Mysql 中获取刚插入的自增长id的值

    insert into user (username,password) VALUES ('); //获取刚插入的自增长id的值 select last_insert_id(); 在MySQL中,使用 ...

  10. KafkaAPI实战

    新旧API使用 Flume和Kafka集成: Kafka有两套API: 过时的API 和新API 准备工作 <dependencies> <dependency> <gr ...