一、通过Hive CLI(command line interface)方式启动
$ bin/hive
15/10/20 15:12:01 INFO Configuration.deprecation: mapred.input.dir.recursive is deprecated. Instead, use mapreduce.input.fileinputformat.input.dir.recursive
......
hive>
二、通过HiveServer2 and Beeline方式启动
1、先启动HiveServer2
$ bin/hive --service hiveserver2
Starting HiveServer2
15/10/20 15:24:49 INFO Configuration.deprecation: mapred.input.dir.recursive is deprecated. Instead, use mapreduce.input.fileinputformat.input.dir.recursive
......
或者
$ bin/hiveserver2
这里采用了hive的默认配置,也就是hive.server2.thrift.port为10000,hive.server2.thrift.bind.host为localhost
2、接着就能使用java去连接,也可以使用 HiveServer2的CLI去连接语法:bin/beeline -u jdbc:hive2://$HS2_HOST:$HS2_PORT
$ bin/beeline -u jdbc:hive2://localhost:10000
scan complete in 3ms
Connecting to jdbc:hive2://localhost:10000
......
Connected to: Hive (version 0.12.0)
Driver: Hive (version 0.12.0)
Transaction isolation: TRANSACTION_REPEATABLE_READ
Beeline version 0.12.0 by Apache Hive
0: jdbc:hive2://localhost:10000>
连接成功,测试一下:
0: jdbc:hive2://localhost:10000> show databases;
+----------------+
| database_name |
+----------------+
| default |
| study |
| study2 |
+----------------+
3 rows selected (0.458 seconds)
三、总结
HiveServer2是 Hive 0.11版本开始有的,HiveServer2是HiveServer的升级版,它们都是以Thrift框架为基础。HiveServer2相对于HiveServer和Hive CLI,HiveServer2增加了新的功能,它支持多客户端的并发和认证,而且为开放API,如JDBC、ODBC提供了更好的支持。所以推荐使用的是HiveServer2。
参考资料
https://cwiki.apache.org/confluence/display/Hive/GettingStarted
https://cwiki.apache.org/confluence/display/Hive/Setting+Up+HiveServer2