Command Line Installation
Also available as:
PDF
loading table of contents...

Setting Up the Database for the Hive Metastore

Use the following steps to set up the database for your Hive Metastore. This step must be performed when you start the metastore for the first time.

  1. Initialize the Hive Metastore database schema:

    $HIVE_HOME/bin/schematool -initSchema -dbType $databaseType

    The value for $databaseType can be derby, mysql, oracle, mssql, or postgres.

    $HIVE_HOME is by default configured to usr/hdp/current/hive.

  2. Turn off autocreation of schemas. Edit hive-site.xml to set the value of datanucleus.autoCreateSchema to false:

    <property>
         <name>datanucleus.autoCreateSchema</name>
         <value>false</value>
         <description>Creates necessary schema on a startup if one doesn't exist</ description>
    </property> 
  3. Start the Hive Metastore service.

    su - $HIVE_USER -c "nohup /grid/0/hdp/current/hive-metastore/bin/hive --service metastore>/var/log/hive/hive.out 2>/var/log/hive/hive.log &"

    [Note]Note

    You might receive the following error after running the su - hive command:

    su hive This account is currently not available.

    If you get this error, you might need to reassign the $HIVE_USER shell. You can confirm this by looking for the following line in etc/passwd:

    hive:x:493:493:Hive:/var/lib/hive:/sbin/nologin63

    This indicates that the $HIVE_USER is assigned to the sbin/nologin shell, which blocks access. You can use the following command to assign the $HIVE_USER to the bin/bash shell.

    sudo chsh -s /bin/bash hive

    This command should return the following:

    Changing shell for hive. Shell changed.

    You should then be able to successfully run the su - $HIVE_USER command.

  4. Smoke test Hive.

    • Open Hive command line shell by entering the following in a terminal window:

      hive

    • Run sample commands:

      show databases;create table test(col1 int, col2 string); show tables;

  5. Start HiveServer2:

    • su - $HIVE_USER
      nohup /usr/hdp/current/hive-server2/bin/hiveserver2 >/var/log/hive/hiveserver2.out 2> /var/log/hive/hiveserver2.log &
  6. Smoke test HiveServer2:

    • Open Beeline command line shell to interact with HiveServer2:

       /usr/hdp/current/hive/bin/beeline
    • Establish connection to server:

       !connect jdbc:hive2://$hive.server.full.hostname:10000 $HIVE_USER password org.apache.hive.jdbc.HiveDriver
    • Run sample commands:

      show databases; create table test2(a int, b string); show tables;