Starting, Stopping, and Using HiveServer2 in CDH

HiveServer2 is an improved version of HiveServer that supports Kerberos authentication and multi-client concurrency. You can access HiveServer2 by using the Beeline client.

To start HiveServer2:

sudo service hive-server2 start

To stop HiveServer2:

sudo service hive-server2 stop

To confirm that HiveServer2 is working, start the beeline CLI and use it to execute a SHOW TABLES query on the HiveServer2 process:

$ /usr/lib/hive/bin/beeline
beeline> !connect jdbc:hive2://localhost:10000 username password org.apache.hive.jdbc.HiveDriver
0: jdbc:hive2://localhost:10000> SHOW TABLES;
show tables;
| tab_name  |
No rows selected (0.238 seconds)
0: jdbc:hive2://localhost:10000> 

Using the Beeline CLI

Beeline is the CLI (command-line interface) developed specifically to interact with HiveServer2. It is based on the SQLLine CLI written by Marc Prud'hommeaux.

Use the following commands to start beeline and connect to a running HiveServer2 process. In this example the HiveServer2 process is running on localhost at port 10000:

$ beeline
beeline> !connect jdbc:hive2://localhost:10000 username password org.apache.hive.jdbc.HiveDriver
0: jdbc:hive2://localhost:10000>
If you use TLS/SSL encryption, discussed later, the JDBC URL must include specifying ssl=true;sslTrustStore=<path_to_truststore>. Truststore password requirements depend on the version of Java running in the cluster
  • Java 11: the truststore format has changed to PKCS and the truststore password is required; otherwise, the connection fails.
  • Java 8: The trust store password does not need to be specified.
The syntax for the JDBC URL is:

For example:

 $ beeline
 beeline> !connect jdbc:hive2://<host>:8443/;ssl=true;transportMode=http;httpPath=gateway/cdp-proxy-api/hive;sslTrustStore=/<path>/bin/certs/gateway-client-trust.jks;trustStorePassword=changeit          

The password changeit is the Java default trust store password.

There are some Hive CLI features that are not available with Beeline. For example:
  • Beeline does not show query logs like the Hive CLI
  • When adding JARs to HiveServer2 with Beeline, the JARs must be on the HiveServer2 host.

At present the best source for documentation on Beeline is the original SQLLine documentation.