Start Hiveserver2, Connect Through Beeline and Run Hive Queries

Hiveserver2

HiveServer2 is an enhanced Hive server designed for multi-client concurrency and improved authentication. It also provides better support for clients connecting through JDBC and ODBC.

Start Hiverserver2

We have our hive installation under the directory – /home/hadoop/hive. Go to the ‘bin‘ directory under hive installation directory. To start the Hiveserver2 run the following script.

/home/hadoop/hive/bin> ./hiveserver2

By default hiverserver2 will listen on port 10000 for incoming requests. Open one more terminal and check whether hiveserver2 has started.

/home/hadoop/hive/bin> netstat -nlp | grep 10000
tcp  0  0 0.0.0.0:10000    0.0.0.0:*      LISTEN     21845/java

Our hiveserver2 is started with a process id of 21845.

Beeline

It’s a JDBC client based on the SQLLine CLI . Beeline connects to a remote HiveServer2 instance using JDBC.

Connect to hiveserver2

Option 1:- beeline -u  <url> -n <username> -p <Password>

/home/hadoop/hive/bin> ./beeline -u jdbc:hive2://localhost:10000 -n hadoopUser -p hadoopPassword
#connection established to hiveserver2, now execute hive queries
0: jdbc:hive2://localhost:10000> show databases;
+----------------+--+
| database_name  |
+----------------+--+
| default        |
+----------------+--+

Option 2:- Using beeline command – !connect,   it allows to connect to a hive server.

/home/hadoop/hive/bin> ./beeline
#beeline shell will start, now connect to the hiveserver2
beeline> !connect jdbc:hive2://localhost:10000 hadoopUser hadoopPassword
#connection established, now execute hive queries
0: jdbc:hive2://localhost:10000> show databases;
+----------------+--+
| database_name  |
+----------------+--+
| default        |
+----------------+--+

Running hive queries script using beeline

We have a script myscript.hql containing hive queries. If we want to run the hive queries from this file using beeline, then we can use the -f option to specify the script filename.

./beeline -u jdbc:hive2://localhost:10000 -n hadoopUser -p hadoopPassword  -f myscript.hql

 

2 Comments

  1. Pingback: Setup Hive 1.x | My IT Learnings

  2. Pingback: Configure Hive Metastore on MySQL | My IT Learnings

Leave a Reply

Your email address will not be published. Required fields are marked *