设为首页 加入收藏

TOP

hive:后台启动、和脚本化运行
2019-02-12 01:02:46 】 浏览:81
Tags:hive: 后台 启动 脚本 运行
版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/fly910905/article/details/82800281

hive使用方式

最基本使用方式

启动一个hive交互shell

bin/hive

hive>

设置一些基本参数,让hive使用起来更便捷,比如:

让提示符显示当前库:

hive>sethive.cli.print.current.db=true;

显示查询结果时显示字段名称:

hive>sethive.cli.print.header=true;

但是这样设置只对当前会话有效,重启hive会话后就失效,解决办法:

在linux的当前用户主(根)目录中,编辑一个.hiverc文件,将参数写入其中:

vi.hiverc

sethive.cli.print.header=true;
sethive.cli.print.current.db=true;

启动hive服务使用

启动hive的服务:

[root@hdp20-04hive-1.2.1]#bin/hiveserver2-hiveconfhive.root.logger=DEBUG,console

上述启动,会将这个服务启动在前台如果要启动在后台,则命令如下:

nohupbin/hiveserver21>/dev/null2>&1&
  • &后台输出
  • 1,标准输出
  • 2,错误输出
  • /dev/null,Linux中的黑洞,表示不存储信息;
  • nohup,用户即使退出,程序也会在后台运行

启动成功后,可以在别的节点上用beeline去连接

方式(1)

[root@hdp20-04hive-1.2.1]#bin/beeline回车,进入beeline的命令界面

输入命令连接hiveserver2

beeline>!connectjdbc:hive2//mini1:10000

(hadoop01是hiveserver2所启动的那台主机名,端口默认是10000)

方式(2)

启动时直接连接:

bin/beeline-ujdbc:hive2://mini1:10000-nroot

接下来就可以做正常sql查询了

脚本化运行

大量的hive查询任务,如果用交互式shell来进行输入的话,显然效率及其低下,因此,生产中更多的是使用脚本化运行机制:

该机制的核心点是:hive可以用一次性命令的方式来执行给定的hql语句

[root@hdp20-04~]#hive-e"insertintotablet_destselect*fromt_src;"

然后,进一步,可以将上述命令写入shell脚本中,以便于脚本化运行hive任务,并控制、调度众多hive任务,示例如下:

vit_order_etl.sh

#!/bin/bash
hive-e"select*fromdb_order.t_order"
hive-e"select*fromdefault.t_user"
hql="createtabledefault.t_bashasselect*fromdb_order.t_order"
hive-e"$hql"

如果要执行的hql语句特别复杂,那么,可以把hql语句写入一个文件:

vix.hql

select*fromdb_order.t_order;
selectcount(1)fromdb_order.t_user;

然后,用hive-f/root/x.hql来执行

】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇hive 中如何使用split字符串分割.. 下一篇Hive 处理CSV格式文件数据

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目