Starting Apache Hive
Also available as:
PDF

Start a Hive shell locally

You can start the Hive shell, which uses Beeline in the background, to enter HiveQL commands on the command line of a node in a cluster.

The architectural changes in Hive 3 support only Beeline for querying Hive from the command line.On a Hive cluster, you type hive followed by RETURN to start a Hive shell. From the Hive shell, you can enter HiveQL commands. After connecting to Hive, you see a prompt that resembles the following example:
0: jdbc:hive2://myhost.org:2181,>
The prompt consists of the following components:
  • jdbc: The Java Database Connectivity protocol designator
  • hive2: The HiveServer protocol designator in HDP 3 for using Hive 3
  • myhost.org: The fully-qualified domain name (FQDN) of the node that hosts HiveServer
  • 2181: The hive.zookeeper.client.port defined in /etc/hive/conf/hive-site.xml
  • You added the Hive service on the cluster, using Ambari for example, and the following components are running:
    • HiveServer
    • Hive Metastore
    • A database for the metastore, such as the default MySQL Server
    • Hive clients
  • You have a user name and password for connecting to Hive.
  • You have a network connection to Beeline.
  1. On a node in your cluster, start Beeline in the background and a Hive shell in the foreground:
    > hive
  2. Enter your user name and password for accessing Hive.
    The Hive 3 connection message appears, followed by the Hive prompt for entering HiveQL queries on the command line:
    Connected to: Apache Hive (version 3.1.0.3.0.0.0-1634)
    Driver: Hive JDBC (version 3.1.0.3.0.0.0-1634)
    Transaction isolation: TRANSACTION_REPEATABLE_READ
    Beeline version 3.1.0.3.0.0.0-1634 by Apache Hive
    
    0: jdbc:hive2://myhost.org:2181,>
  3. Enter a HiveQL query.
    SHOW DATABASES;
    Hive creates two databases when you add the Hive service to a cluster: information_schema and sys. All Metastore tables are mapped into your tablespace and are available in sys. The information_schema data reveals the state of the system, similar to sys database data, but in a user-friendly way. You can query information_schema using SQL standard queries, which are portable from one DBMS to another.
    Output is:
    +---------------------+
    |    database_name    |
    +---------------------+
    | default             |
    | information_schema  |
    | sys                 |
    +---------------------+
  4. Exit the Beeline and Hive shells.
    !quit