hive--beeline使用

  hive beeline客户端方式采用JDBC方式借助于Hive Thrift服务访问Hive数据仓库。
  HiveThrift(HiveServer)是Hive中的组件之一,设计目的是为了实现跨语言轻量级访问Hive数据仓库,有Hiveserver和 Hiveserver2两个版本,两者不兼容,使用中要注意区分。体现在启动HiveServer的参数和jdbc:hiveX的参数上。

启动hiveserver2和beeline
  进入$HIVE_HOME/bin下,执行

./hiveserver2

即启动了服务端。然后我们启动beeline客户端,根据hive官网文档,有两种方式连接启动的服务。
1、首先启动beenline

./beenline

然后在交互窗口执行

!connect jdbc:hive2://localhost:10000 hadoop hadoop

这里hadoop和hadoop分别为用户名和密码。
2、直接执行

 beeline -u jdbc:hive2://localhost:10000/default -n hadoop

但是我在执行的时候报错了

[hadoop@hadoop001 bin]$ beeline -u jdbc:hive2://localhost:10000/default -n hadoop
Connecting to jdbc:hive2://localhost:10000/default
18/12/11 16:00:29 INFO jdbc.Utils: Supplied authorities: localhost:10000
18/12/11 16:00:29 INFO jdbc.Utils: Resolved authority: localhost:10000
18/12/11 16:00:29 INFO jdbc.HiveConnection: Will try to open client transport with JDBC Uri: jdbc:hive2://localhost:10000/default
18/12/11 16:00:29 ERROR jdbc.HiveConnection: Error opening session
org.apache.thrift.TApplicationException: Required field 'client_protocol' is unset! Struct:TOpenSessionReq(client_protocol:null, configuration:{use:database=default})
	at org.apache.thrift.TApplicationException.read(TApplicationException.java:111)
	at org.apache.thrift.TServiceClient.receiveBase(TServiceClient.java:79)
	at org.apache.hive.service.cli.thrift.TCLIService$Client.recv_OpenSession(TCLIService.java:156)
	at org.apache.hive.service.cli.thrift.TCLIService$Client.OpenSession(TCLIService.java:143)
	at org.apache.hive.jdbc.HiveConnection.openSession(HiveConnection.java:583)
	at org.apache.hive.jdbc.HiveConnection.<init>(HiveConnection.java:192)
	at org.apache.hive.jdbc.HiveDriver.connect(HiveDriver.java:105)
	at java.sql.DriverManager.getConnection(DriverManager.java:664)
	at java.sql.DriverManager.getConnection(DriverManager.java:208)
	at org.apache.hive.beeline.DatabaseConnection.connect(DatabaseConnection.java:142)
	at org.apache.hive.beeline.DatabaseConnection.getConnection(DatabaseConnection.java:207)
	at org.apache.hive.beeline.Commands.connect(Commands.java:1149)
	at org.apache.hive.beeline.Commands.connect(Commands.java:1070)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:497)
	at org.apache.hive.beeline.ReflectiveCommandHandler.execute(ReflectiveCommandHandler.java:52)
	at org.apache.hive.beeline.BeeLine.dispatch(BeeLine.java:970)
	at org.apache.hive.beeline.BeeLine.initArgs(BeeLine.java:707)
	at org.apache.hive.beeline.BeeLine.begin(BeeLine.java:757)
	at org.apache.hive.beeline.BeeLine.mainWithInputRedirection(BeeLine.java:484)
	at org.apache.hive.beeline.BeeLine.main(BeeLine.java:467)
Error: Could not establish connection to jdbc:hive2://localhost:10000/default: Required field 'client_protocol' is unset! Struct:TOpenSessionReq(client_protocol:null, configuration:{use:database=default}) (state=08S01,code=0)
Beeline version 1.2.1.spark2 by Apache Hive

仔细查看日志,发现启动的beenline不是Hive的beenline,而是spark的beenline。这是因为在我的机器上装有spark,而且配置到了环境变量中。所以应该在$HIVE_HOME/bin目录下执行

./ beeline -u jdbc:hive2://localhost:10000/default -n hadoop

连接成功。可以执行和hive客户端访问方式一样的操作。

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值