当前位置:   article > 正文

hive--beeline使用_beeline -u连接hive

beeline -u连接hive

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

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

./hiveserver2
  • 1

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

./beenline
  • 1

然后在交互窗口执行

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

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

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

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

[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
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32

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

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

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

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/小小林熬夜学编程/article/detail/531410
推荐阅读
相关标签
  

闽ICP备14008679号