beeline 是 hive 提供的一個新的命令行工具,基于SQLLine CLI的JDBC客戶端,beeline 與HiveServer2配合使用,支持嵌入模式和遠程模式兩種,可以像hive client一樣訪問本機的hive服務,也可以通過指定ip和連接埠訪問遠程hive服務。
hive 官方是推薦使用beeline,因為它還提供了更為友好的交互方式(類似mysql client)
連接到本機的Hive
[hadoop@localhost ~]$ /srv/apache-hive/bin/beeline -u jdbc:hive2:// SLF4J: Class path contains multiple SLF4J bindings. SLF4J: Found binding in [jar:file:/srv/apache-hive-2.1.1/lib/log4j-slf4j-impl-2.4.1.jar!/org/slf4j/impl/StaticLoggerBinder.class] SLF4J: Found binding in [jar:file:/srv/apache-hadoop-2.8.0/share/hadoop/common/lib/slf4j-log4j12-1.7.10.jar!/org/slf4j/impl/StaticLoggerBinder.class] SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation. SLF4J: Actual binding is of type [org.apache.logging.slf4j.Log4jLoggerFactory] Connecting to jdbc:hive2:// 17/06/29 22:01:16 [main]: WARN session.SessionState: METASTORE_FILTER_HOOK will be ignored, since hive.security.authorization.manager is set to instance of HiveAuthorizerFactory. Connected to: Apache Hive (version 2.1.1) Driver: Hive JDBC (version 2.1.1) 17/06/29 22:01:16 [main]: WARN jdbc.HiveConnection: Request to set autoCommit to false; Hive does not support autoCommit=false. Transaction isolation: TRANSACTION_REPEATABLE_READ Beeline version 2.1.1 by Apache Hive 0: jdbc:hive2://> show databases; OK +----------------+--+ | database_name | +----------------+--+ | default | +----------------+--+ 1 row selected (1.318 seconds) 0: jdbc:hive2://> use default; OK No rows affected (0.03 seconds) 0: jdbc:hive2://> show tables; OK +-----------+--+ | tab_name | +-----------+--+ | invites | | member | | passwd | | v_test | | vipuser | +-----------+--+ 5 rows selected (0.068 seconds) 0: jdbc:hive2://>
連接遠程主機
[hadoop@localhost ~]$ /srv/apache-hive/bin/beeline -u jdbc:hive2://hadoop@localhost:10000 SLF4J: Class path contains multiple SLF4J bindings. SLF4J: Found binding in [jar:file:/srv/apache-hive-2.1.1/lib/log4j-slf4j-impl-2.4.1.jar!/org/slf4j/impl/StaticLoggerBinder.class] SLF4J: Found binding in [jar:file:/srv/apache-hadoop-2.8.0/share/hadoop/common/lib/slf4j-log4j12-1.7.10.jar!/org/slf4j/impl/StaticLoggerBinder.class] SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation. SLF4J: Actual binding is of type [org.apache.logging.slf4j.Log4jLoggerFactory] Connecting to jdbc:hive2://hadoop@localhost:10000 Connected to: Apache Hive (version 2.1.1) Driver: Hive JDBC (version 2.1.1) 17/06/29 23:05:35 [main]: WARN jdbc.HiveConnection: Request to set autoCommit to false; Hive does not support autoCommit=false. Transaction isolation: TRANSACTION_REPEATABLE_READ Beeline version 2.1.1 by Apache Hive 0: jdbc:hive2://hadoop@localhost:10000> show databases; +----------------+--+ | database_name | +----------------+--+ | default | +----------------+--+ 1 row selected (1.332 seconds) 0: jdbc:hive2://hadoop@localhost:10000> use default; No rows affected (0.038 seconds) 0: jdbc:hive2://hadoop@localhost:10000> show tables; +-----------+--+ | tab_name | +-----------+--+ | invites | | member | | passwd | | t_hive | | v_test | | vipuser | +-----------+--+ 6 rows selected (0.049 seconds) 0: jdbc:hive2://hadoop@localhost:10000> select * from member; +--------------+-------------+-------------+---------------+--+ | member.name | member.age | member.sex | member.phone | +--------------+-------------+-------------+---------------+--+ | Neo | 30 | 1 | 13113668890 | +--------------+-------------+-------------+---------------+--+ No rows selected (1.137 seconds) 1: jdbc:hive2://hadoop@localhost:10000>