Beeline Examples

This page shows examples for connecting to HiveServer2 using Beeline.

The following table is a guide for interpreting the examples on this page. In the examples, replace the variables (information in brackets) with your site-specific values. Be sure to remove the brackets when you insert your information:
Variable Description
<hs2_hostname> The name of the host where HiveServer2 is installed.
<database> The database name to connect to.
<username> The JDBC username.
<password> The password for the JDBC user.
<FQDN@realm> Fully qualified domain name & Kerberos realm.

Using Beeline with no Encryption and no Authentication

hive --service beeline
Beeline version 2.3.3-mapr-1901 by Apache Hive
beeline> !connect jdbc:hive2://<hs2_hostname>:10000/<database>;
Connecting to jdbc:hive2://<hs2_hostname>:10000/<database>;
Enter username for jdbc:hive2://<hs2_hostname>:10000/<database>;: <username>
0: jdbc:hive2://<hs2_hostname>:10000/<database> 

Using Beeline with Encryption and no Authentication

hive --service beeline
Beeline version 2.3.3-mapr-1901 by Apache Hive
beeline> !connect jdbc:hive2://<hs2_hostname>:10000/<database>;ssl=true;sslTrustStore=truststore.jks;sslTrustStorePassword=tsp
Connecting to jdbc:hive2://<hs2_hostname>:10000/<database>;ssl=true;sslTrustStore=truststore.jks;sslTrustStorePassword=tsp
Enter username for jdbc:hive2://<hs2_hostname>:10000/<database>;ssl=true;sslTrustStore=truststore.jks;sslTrustStorePassword=tsp: <username>
0: jdbc:hive2://<hs2_hostname>:10000/<database>

Connecting to HiveServer2 with MapR-SASL Authentication

hive --service beeline
Beeline version 2.3.3-mapr-1901 by Apache Hive
beeline> !connect jdbc:hive2://<hs2_hostname>:10000/<database>;auth=maprsasl;ssl=true
Connecting to jdbc:hive2://<hs2_hostname>:10000/<database>;auth=maprsasl;ssl=true
19/01/31 12:15:33 [main]: WARN maprsasl.MaprSaslClient: SASL Server qopProperty: auth-confis different from Client: auth-conf,auth-int,auth.Using Server one
Connected to: Apache Hive (version 2.3.3-mapr-1901)
Driver: Hive JDBC (version 2.3.3-mapr-1901)
Transaction isolation: TRANSACTION_REPEATABLE_READ
0: jdbc:hive2://<hs2_hostname>:10000/<database>

Starting from EEP 6.0.0, with secure by default configuration, it is a default connection string for a secure cluster. For more information, see Configuring JDBC Connection String with SSL Encryption Enabled or Disabled.

Using Beeline with PAM Authentication

hive --service beeline
Beeline version 2.3.3-mapr-1901 by Apache Hive 
beeline> !connect jdbc:hive2://<hs2_hostname>:10000/<database>; 
Connecting to jdbc:hive2://<hs2_hostname>:10000/<database>; 
Enter username for jdbc:hive2://<hs2_hostname>:10000/<database>;: <username>
Enter password for jdbc:hive2://<hs2_hostname>:10000/<database>;: <password>  
Connected to: Apache Hive (version 2.3.3-mapr-1901)
Driver: Hive JDBC (version 2.3.3-mapr-1901)
Transaction isolation: TRANSACTION_REPEATABLE_READ 
0: jdbc:hive2://<hs2_hostname>:10000/<database>

Connecting to HiveServer2 with ZooKeeper

hive --service beeline -u
'jdbc:hive2://zookeeper1.com:5181,zookeeper2.com:5181,zookeeper3.com:5181/;serviceDiscoveryMode=zooKeeper;zooKeeperNamespace=hiveserver2' -n mapr -p

Connecting to HiveServer2 with PAM Authentication and SSL Encryption

hive --service beeline
Beeline version 2.3.3-mapr-1901 by Apache Hive
beeline> !connect jdbc:hive2://<hs2_hostname>:10000/<database>;ssl=true;
Connecting to jdbc:hive2://<hs2_hostname>:10000/<database>;ssl=true;
Enter username for jdbc:hive2://<hs2_hostname>:10000/<database>: <username>
Enter password for jdbc:hive2://<hs2_hostname>:10000/<database>: <password> 
Connected to: Apache Hive (version 2.3.3-mapr)
Driver: Hive JDBC (version 2.3.3-mapr)
Transaction isolation: TRANSACTION_REPEATABLE_READ
0: jdbc:hive2://<hs2_hostname>:10000/<database>

Starting from EEP 6.0.0, with secure-by-default configurations, the default connection string is for a secure cluster. For more information, see Configuring JDBC Connection String with SSL Encryption Enabled or Disabled.

Using Beeline with Kerberos

Beeline must pass the Kerberos principal for HiveServer2 in the JDBC connection string. The connection strings you pass to Beeline must use the principal name that you configured for HiveServer2.

The following example shows a sample Beeline authentication with Kerberos:

hive --service beeline
Beeline version 2.3.3-mapr-1901 by Apache Hive
beeline> !connect jdbc:hive2://<hs2_hostname>:10000/<database>;principal=mapr<FQDN@REALM>
Connecting to jdbc:hive2://<hs2_hostname>:10000/<database>;principal=mapr/<FQDN@REALM>
Transaction isolation: TRANSACTION_REPEATABLE_READ
0: jdbc:hive2://<hs2_hostname>:10000/def> 
Connected to: Apache Hive (version 2.3.3-mapr)
Driver: Hive JDBC (version 2.3.3-mapr)
Transaction isolation: TRANSACTION_REPEATABLE_READ
0: jdbc:hive2://<hs2_hostname>:10000/<database>

Using Beeline with Encryption but no Authentication (truststore parameters passed as JVM arguments)

Hive --service beeline
Beeline version 2.3.3-mapr-1901 by Apache Hive
beeline> !connect jdbc:hive2://<hs2_hostname>:1000/<database>;ssl=true
Connecting to jdbc:hive2://<hs2_hostname>:10000/<database>;ssl=true
Enter username for jdbc:hive2://<hs2_hostname>:10000/<database>;ssl=true: <username>
Enter password for jdbc:hive2://<hs2_hostname>:10000/<database>;ssl=true: <password> 
Connected to: Apache Hive (version 2.3.3-mapr)
Driver: Hive JDBC (version 2.3.3-mapr)
Transaction isolation: TRANSACTION_REPEATABLE_READ
0: jdbc:hive2://<hs2_hostname>:10000/<database>

Generating a Kerberos Ticket

Use the kinit utility to generate the ticket and then use klist to verify that a ticket exists.

# kinit <username>/<FQDN@REALM>
# klist
 
Credentials cache: API:501:9
        Principal: username/<FQDN@REALM>
    Cache version: 0
 
Server: krbtgt/<FQDN@REALM>
Client: username/<FQDN@REALM>
Ticket etype: aes128-cts-hmac-sha1-96
Ticket length: 256
Auth time:  Jun 11 10:01:48 2014
End time:   Jun 12 18:01:34 2014
Renew till: Jun 18 10:01:48 2014
Ticket flags: pre-authent, initial, renewable, forwardable
Addresses: addressless