hive执行方式

cli

客户端启动hive

hive --service metastore &

服务器端登录

hive

JDBC方式(&&Beeline)

服务端开启hiveserver2

>hive --service hiveserver2

客户的通过beeline两种方式连接到hive
1)
直接启动beeline连接指定的数据库

beeline -u jdbc:hive2://hive服务器地址:10000/default -n root

2)
启动beeline之后再连接数据库

>beeline
beeline>!connect jdbc:hive2://<host>:<port>/<db> root 123

密码123随便,因为只要告诉hadoop连接的是root用户,Hadoop就认为是哪个用户,密码随便输入
3)
通过java程序,不再赘述。

退出beeline

0: jdbc:hive2://cdh2:10000/data1> !close
beeline> !quit

注意

beeline> show databases;
No current connection

需要编辑hadoop下core-site.xml添加如下,其中xxx是hdfs数据的拥有者
在这里插入图片描述

<property>
   <name>hadoop.proxyuser.xxx.hosts</name>
   <value>*</value>
</property>
<property>
  <name>hadoop.proxyuser.xxx.groups</name>
  <value>*</value>
</property>

脚本执行hive

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 “SQL”执行;

[root@cdh3 ~]#hive -e "select id from data1.bucket1"

hive -f SQL文件执行;
将sql保存到一个文件中demo.sql
demo.sql的内容:

select * from data1.bucket1 where id = '1';
[root@cdh3 ~]# hive -f demo.sql 
OK
1	小明1	["lol","book","movie"]	{"beijing":"xisanqi","shanghai":"pudong"}
Time taken: 8.151 seconds, Fetched: 1 row(s)

通过hive -hivevar 加参数

test.sh的内容

#!/usr/bin/env bash

start_date="$1"
hive -hivevar p_date=${start_date} -f /data/apps/yqg_datatask_cheetah/task/tempdata/load_tmp_export_asset_full_to_ods_yqg/hivescript.sql

Hive Web GUI接口

web界面安装:
下载源码包apache-hive-*-src.tar.gz
将hwi war包放在 hive/lib/,制作方法:将hwi/web/*里面所有的文件打成war包
cd apache-hive-1.2.1-src/hwi/web
jar -cvf hive-hwi.war *
复制tools.jar(在jdk的lib目录下)到hive/lib下
修改hive-site.xml

修改hive配置文件hive-site.xml添加以下配置内容:
启动metastore服务的node3上配置该信息

<property>
    <name>hive.hwi.listen.host</name>
    <value>0.0.0.0</value>
  </property>
  <property>
    <name>hive.hwi.listen.port</name>
    <value>9999</value>
  </property>
  <property>
    <name>hive.hwi.war.file</name>
    <value>lib/hive-hwi.war</value>
 </property>

启动hwi服务(端口号9999)

hive --service hwi

浏览器通过以下链接来访问
http://node3:9999/hwi/

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值