This topic describes how to connect to Hive from an E-MapReduce (EMR) cluster.
Prerequisites
You have logged on to an EMR cluster. For more information, see Log on to a cluster.
Method 1: Use the Hive client
- For a common cluster, run the following command:
hive
The following information is returned:Logging initialized using configuration in file:/etc/ecm/hive-conf-2.3.5-2.0.3/hive-log4j2.properties Async: true Hive-on-MR is deprecated in Hive 2 and may not be available in the future versions. Consider using a different execution engine (i.e. spark, tez) or using Hive 1.X releases.
- For a high-security cluster, perform the following steps:
- Run the following command to perform authentication:
kinit -kt /etc/ecm/hive-conf/hive.keytab hive/emr-header-1.cluster-xxx@EMR.xxx.COM
Replace
xxx
in the command with the hostname of the emr-header-1 node. You can run thehostname
command on the emr-header-1 node to obtain the hostname.You can also use the user management feature to add a user. Before you connect to Hive, run thekinit username
command and enter the password of the user to perform authentication. For more information about how to add a user, see Manage user accounts.- Run the following command to perform authentication:
kinit username
- Enter the password of the user.
Password for username@EMR.xxx.COM:
- Run the following command to perform authentication:
- Connect to Hive.
hive
The following information is returned:Logging initialized using configuration in file:/etc/ecm/hive-conf-2.3.5-2.0.3/hive-log4j2.properties Async: true Hive-on-MR is deprecated in Hive 2 and may not be available in the future versions. Consider using a different execution engine (i.e. spark, tez) or using Hive 1.X releases.
- Run the following command to perform authentication:
Method 2: Use Beeline
- For a common cluster, run the following command:
beeline -u jdbc:hive2://emr-header-1:10000
The following information is returned:Connecting to jdbc:hive2://emr-header-1:10000 Connected to: Apache Hive (version 2.3.5) Driver: Hive JDBC (version 2.3.5) Transaction isolation: TRANSACTION_REPEATABLE_READ Beeline version 2.3.5 by Apache Hive 0: jdbc:hive2://emr-header-1:10000>
- For a high-availability cluster, run the following command:
beeline -u 'jdbc:hive2://emr-header-1:2181,emr-header-2:2181,emr-header-3:2181/;serviceDiscoveryMode=zooKeeper;zooKeeperNamespace=hiveserver2'
The following information is returned:Connecting to jdbc:hive2://emr-header-1:2181,emr-header-2:2181,emr-header-3:2181/;serviceDiscoveryMode=zooKeeper;zooKeeperNamespace=hiveserver2 21/08/27 14:37:03 [main]: INFO jdbc.HiveConnection: Connected to emr-header-1.cluster-***:10000 Connected to: Apache Hive (version 3.1.2) Driver: Hive JDBC (version 3.1.2)Transaction isolation: TRANSACTION_REPEATABLE_READ Beeline version 3.1.2 by Apache Hive 0: jdbc:hive2://emr-header-1:2181,emr-header->
- For a high-security cluster, perform the following steps:
- Run the following command to perform authentication:
kinit -kt /etc/ecm/hive-conf/hive.keytab hive/emr-header-1.cluster-xxx@EMR.xxx.COM
Replace
xxx
in the command with the hostname of the emr-header-1 node. You can run thehostname
command on the emr-header-1 node to obtain the hostname.You can also use the user management feature to add a user. Before you connect to Beeline, run thekinit username
command and enter the password of the user to perform authentication. For more information about how to add a user, see Manage user accounts.- Run the following command to perform authentication:
kinit username
- Enter the password of the user.
Password for username@EMR.xxx.COM:
- Run the following command to perform authentication:
- Connect to Beeline.
beeline -u "jdbc:hive2://emr-header-1:10000/;principal=hive/emr-header-1.cluster-xxx@EMR.xxx.COM"
Note TheJDBC
URL must be enclosed in a pair of double quotation marks (").The following information is returned:Connecting to jdbc:hive2://emr-header-1:10000/;principal=hive/emr-header-1.cluster-202618@EMR.202618.COM Connected to: Apache Hive (version 2.3.5) Driver: Hive JDBC (version 2.3.5) Transaction isolation: TRANSACTION_REPEATABLE_READ Beeline version 2.3.5 by Apache Hive 0: jdbc:hive2://emr-header-1:10000/>
- Run the following command to perform authentication: