Archives of Support Questions (Read Only)

This is an archived board for historical reference. Information and links may no longer be available or relevant
Announcements
This board is archived and read-only for historical reference. To ask a new question, please post a new topic on the appropriate active board.

Connect to Hive with UNIX/HDFS user via beeline

avatar
New Member

How can I connect to Hive with a UNIX/HDFS user via beeline?

Let's say I have a UNIX user named "newuser". I tried the following, but apparently I am doing something wrong.

% su - newuser
% beeline
beeline>!connect -n newuser -p jdbc:mysql://my.host.com/hive
1 ACCEPTED SOLUTION

avatar
Master Mentor

@Maxim Neaga

What error are you gettin while connecting to hive using beeling?

Are you sure that the URL which you entered is correct... Becaue looks like you are trying to connect to MySQL database instead of hiveServer2.

Following is what i tried:

# useradd test
# usermod -G hadoop test
# su - hdfs -c "hdfs dfs -mkdir /user/test"
# su - hdfs -c "hdfs dfs -chown -R test:hadoop /user/test"

.

The connect to Beeline using test user:

# su - test
$ beeline
Beeline version 1.2.1000.2.6.5.0-292 by Apache Hive
beeline> !connect jdbc:hive2://newhwx1.example.com:2181,newhwx2.example.com:2181,newhwx3.example.com:2181/;serviceDiscoveryMode=zooKeeper;zooKeeperNamespace=hiveserver2

.

Execute queries:

beeline> !connect jdbc:hive2://newhwx1.example.com:2181,newhwx2.example.com:2181,newhwx3.example.com:2181/;serviceDiscoveryMode=zooKeeper;zooKeeperNamespace=hiveserver2


Connecting to jdbc:hive2://newhwx1.example.com:2181,newhwx2.example.com:2181,newhwx3.example.com:2181/;serviceDiscoveryMode=zooKeeper;zooKeeperNamespace=hiveserver2
Enter username for jdbc:hive2://newhwx1.example.com:2181,newhwx2.example.com:2181,newhwx3.example.com:2181/;serviceDiscoveryMode=zooKeeper;zooKeeperNamespace=hiveserver2: 
Enter password for jdbc:hive2://newhwx1.example.com:2181,newhwx2.example.com:2181,newhwx3.example.com:2181/;serviceDiscoveryMode=zooKeeper;zooKeeperNamespace=hiveserver2: 
Connected to: Apache Hive (version 1.2.1000.2.6.5.0-292)
Driver: Hive JDBC (version 1.2.1000.2.6.5.0-292)
Transaction isolation: TRANSACTION_REPEATABLE_READ


0: jdbc:hive2://newhwx1.example.com:2181,newh> show databases;
+----------------+--+
| database_name  |
+----------------+--+
| default        |
+----------------+--+
1 row selected (0.627 seconds)

Here the URL needs to be correct. For example in above case i am connecting to HiveServer2 using the Zookeepre quorum which i found in the Ambari Hive Summary page.

jdbc:hive2://newhwx1.example.com:2181,newhwx2.example.com:2181,newhwx3.example.com:2181/;serviceDiscoveryMode=zooKeeper;zooKeeperNamespace=hiveserver2

.

Hive URL you can get from here in Ambari UI:

86387-hive-url.png

.

View solution in original post

1 REPLY 1

avatar
Master Mentor

@Maxim Neaga

What error are you gettin while connecting to hive using beeling?

Are you sure that the URL which you entered is correct... Becaue looks like you are trying to connect to MySQL database instead of hiveServer2.

Following is what i tried:

# useradd test
# usermod -G hadoop test
# su - hdfs -c "hdfs dfs -mkdir /user/test"
# su - hdfs -c "hdfs dfs -chown -R test:hadoop /user/test"

.

The connect to Beeline using test user:

# su - test
$ beeline
Beeline version 1.2.1000.2.6.5.0-292 by Apache Hive
beeline> !connect jdbc:hive2://newhwx1.example.com:2181,newhwx2.example.com:2181,newhwx3.example.com:2181/;serviceDiscoveryMode=zooKeeper;zooKeeperNamespace=hiveserver2

.

Execute queries:

beeline> !connect jdbc:hive2://newhwx1.example.com:2181,newhwx2.example.com:2181,newhwx3.example.com:2181/;serviceDiscoveryMode=zooKeeper;zooKeeperNamespace=hiveserver2


Connecting to jdbc:hive2://newhwx1.example.com:2181,newhwx2.example.com:2181,newhwx3.example.com:2181/;serviceDiscoveryMode=zooKeeper;zooKeeperNamespace=hiveserver2
Enter username for jdbc:hive2://newhwx1.example.com:2181,newhwx2.example.com:2181,newhwx3.example.com:2181/;serviceDiscoveryMode=zooKeeper;zooKeeperNamespace=hiveserver2: 
Enter password for jdbc:hive2://newhwx1.example.com:2181,newhwx2.example.com:2181,newhwx3.example.com:2181/;serviceDiscoveryMode=zooKeeper;zooKeeperNamespace=hiveserver2: 
Connected to: Apache Hive (version 1.2.1000.2.6.5.0-292)
Driver: Hive JDBC (version 1.2.1000.2.6.5.0-292)
Transaction isolation: TRANSACTION_REPEATABLE_READ


0: jdbc:hive2://newhwx1.example.com:2181,newh> show databases;
+----------------+--+
| database_name  |
+----------------+--+
| default        |
+----------------+--+
1 row selected (0.627 seconds)

Here the URL needs to be correct. For example in above case i am connecting to HiveServer2 using the Zookeepre quorum which i found in the Ambari Hive Summary page.

jdbc:hive2://newhwx1.example.com:2181,newhwx2.example.com:2181,newhwx3.example.com:2181/;serviceDiscoveryMode=zooKeeper;zooKeeperNamespace=hiveserver2

.

Hive URL you can get from here in Ambari UI:

86387-hive-url.png

.