How to Install and Configure HIVE Metastore with MYSQL

โšก Smart Summary

Hive metastore stores every table definition, column name and data type behind Apache Hive, and moving that repository from the default Derby database to MySQL is what allows several users to connect at once.

  • ๐Ÿ—„๏ธ What it holds: The metastore keeps schema metadata in relational tables, while the table data itself stays on HDFS.
  • ๐Ÿšซ Why Derby fails: The bundled Derby metastore accepts one active session, which rules it out for any shared or production cluster.
  • ๐Ÿ”ง Four properties: ConnectionURL, ConnectionDriverName, ConnectionUserName and ConnectionPassword in hive-site.xml point Hive at MySQL.
  • ๐Ÿ”— Driver placement: The MySQL JDBC connector must be linked into the Hive lib directory before any connection attempt succeeds.
  • ๐Ÿงฑ Schema first: The schematool utility creates the metastore tables, and Hive refuses to start against an uninitialised schema.
  • ๐Ÿ”Ž Verify in MySQL: A table created in Hive appears immediately as a row in the TBLS table of the metastore database.

How to install and configure the Hive metastore with MySQL

What is HIVE Metastore?

Hive metastore is a repository that stores metadata (column names, data types, comments, etc.) related to Apache Hive using MySQL or PostgreSQL. This Hive metastore is implemented using tables in a relational database.

Nothing in the metastore holds the rows themselves. The records stay on HDFS, and the metastore only records where each table lives and what its columns are called, which is why losing it costs the schema rather than the data.

Why to Use MySQL in Hive as Metastore

The metastore backend is a choice, not a fixed part of Hive, and the shipped default is deliberately minimal. Three limits push almost every installation away from it.

  • By default, Hive comes with the Derby database as metastore.
  • Derby can support only a single active user at a time.
  • Derby is not recommended in a production environment.

So the solution here is

  • Use MySQL as meta storage at the backend to connect multiple users with Hive at a time
  • MySQL is the best choice for the standalone metastore

How to Install and Configure Hive Metastore to MySQL Database

The nine steps below run in order on a machine that already has Hadoop and Hive installed. Each step ends with a screenshot of the actual terminal or shell output.

Step 1) Install MySQL Server
In this step, we are going to perform two tasks

  1. Installation of mysql-server
  2. Checking the mysql-server and its process

Using the sudo apt-get install mysql-server command, we can download MySQL server. Install MySQL as shown in the screenshot below.

Terminal running sudo apt-get install mysql-server on Ubuntu

After successful installation, MySQL will run as shown in the screenshot below, where the process check confirms the service is up.

Terminal confirming the mysql-server process is running after installation

Step 2) Install MySQL Java Connector
Installing the MySQL Java connector. This is for Java dependencies and connection purposes, because Hive reaches MySQL over JDBC. The next screenshot shows the package installation.

Terminal installing the libmysql-java MySQL Java connector package

Step 3) Create soft link for connector
Creating a soft link for the connector in the Hive lib directory. This is the soft link between Java and MySQL, and it is what puts the driver JAR on the Hive classpath. The command and its result appear below.

Terminal creating a soft link for the MySQL connector JAR in the Hive lib directory

Step 4) Configuring MySQL storage in Hive
The MySQL shell has to be opened as the root account before any Hive user can be created, as shown next.

Terminal opening the MySQL shell with the mysql -u root -p command

  • Type mysql –u root –p followed by the password
  • Here –u represents the root username and –p denotes the password
  • After entering the above command, the user has to enter a valid password and then press enter
  • Then it will enter into MySQL shell mode

Step 5) Create username and password
Creating a username and password for MySQL, and granting privileges. The screenshot below shows the three statements running inside the MySQL shell.

MySQL shell creating the hiveuser account and granting privileges

We have to execute the commands as shown below,

mysql> CREATE USER 'hiveuser'@'%' IDENTIFIED BY 'hivepassword'; 
mysql> GRANT all on *.* to 'hiveuser'@localhost identified by 'hivepassword';
mysql>  flush privileges;

On MySQL 8 the combined form of the second statement no longer parses, because IDENTIFIED BY was removed from GRANT. Create the account first and then grant to it, and repeat the CREATE USER line for the localhost host as well as for the wildcard host.

Step 6) Configuring hive-site.xml

  • After Step 5 assigns a username and password to the MySQL database and grants privileges.
  • Here we will configure some properties in Hive to get a connection with the MySQL database.

The configuration file is opened from the Hive conf directory, as the next screenshot shows.

Terminal opening hive-site.xml for editing in the Hive conf directory

The screenshot that follows shows the finished file with all four properties in place.

hive-site.xml showing the four javax.jdo.option connection properties

From the above screenshot, we observe the following. Here we are defining 4 properties that are necessary to establish MySQL as the metastore in Hive.

These are as follows:

  1. This property is for the connection URL. Here we are defining ConnectionURL in this property. It acts as the JDBC connection string and it represents the metastore location as well
  2. This property is for the connection driver name. Here com.mysql.jdbc.Driver is the value we have to mention in the value tag
  3. This property is used for defining the connection user name. In this, we defined “hiveuser” as the user name
  4. This property is used for mentioning the connection password. In this, we defined “hivepassword” as the user password

Once the properties are placed in hive-site.xml we have to manually save (Ctrl+S) and close the file. After closing this file, we have to create a Hive table and check the table details in MySQL storage.

Place this code in hive-site.xml

hive-site.xml

<configuration>
	<property>
		<name>javax.jdo.option.ConnectionURL</name>
		<value>jdbc:mysql://localhost/metastore?createDatabaseIfNotExist=true</value>
		<description>metadata is stored in a MySQL server</description>
	</property>
	<property>
		<name>javax.jdo.option.ConnectionDriverName</name>
		<value>com.mysql.jdbc.Driver</value>
		<description>MySQL JDBC driver class</description>
	</property>
	<property>
		<name>javax.jdo.option.ConnectionUserName</name>
		<value>hiveuser</value>
		<description>user name for connecting to mysql server</description>
	</property>
	<property>
		<name>javax.jdo.option.ConnectionPassword</name>
		<value>hivepassword</value>
		<description>password for connecting to mysql server</description>
	</property>
</configuration>

Two values above depend on the connector version in use. MySQL Connector/J 8 renamed the driver class to com.mysql.cj.jdbc.Driver, and it also expects an explicit port and SSL setting, so a modern URL usually reads jdbc:mysql://localhost:3306/metastore?createDatabaseIfNotExist=true&useSSL=false. Because the password sits in clear text, the file should be readable only by the Hive service account.

Step 7) Create table
Create table “guru99” in Hive, as shown in the Hive shell below.

Hive shell creating the guru99 table with an integer and a string column

From the above screenshot, we can observe the following

  • Creation of a table named “guru99” with two column names
  • The column names are mentioned with their data types, one an integer and the other a string

In the next step, we are going to check whether it is stored in MySQL or not.

Step 8) Enter into MySQL shell mode
The metastore database is selected first, and the table listing that follows is shown below.

MySQL shell running use metastore and show tables to list metastore tables

From the above screenshot, we can observe the following

  • First we have to select the database with “use metastore”
  • Once the metastore is chosen we can check the tables present in it by using the “show tables” command as shown in the screenshot
  • Whatever tables are created in Hive, the metadata corresponding to those tables is stored under TBLS in the MySQL database
  • The “guru99” table is created in Hive, so the corresponding metadata is stored in MySQL under TBLS

Step 9) Enter select * from TBLS
Checking whether the created table is present in MySQL or not. The query and its result appear in the screenshot below.

MySQL shell running select * from TBLS and displaying the guru99 table row

By entering select * from TBLS, it is going to display the tables that we created in Hive shell mode

From the above screenshot we can observe following things:

  • The table name “guru99” that was created in Hive can be displayed in MySQL shell mode
  • Beside this, it will also provide information like table creation time, accessed time and other properties as shown in the screenshot above

How to Initialize the Hive Metastore Schema with schematool

The createDatabaseIfNotExist flag in the connection URL creates an empty metastore database, but it does not create the roughly seventy tables that Hive expects inside it. On Hive 1.x and later that job belongs to the schematool utility, and skipping it is the single most common reason a freshly configured metastore refuses to start.

$HIVE_HOME/bin/schematool -dbType mysql -initSchema

The command reads the same four properties from hive-site.xml, connects with the hiveuser account, and runs the bundled SQL script that matches the Hive version. A successful run ends with a completion message, after which the state can be confirmed at any time.

$HIVE_HOME/bin/schematool -dbType mysql -info

The flags below cover the whole life of a metastore schema.

Option What it does
-dbType Names the backend, such as mysql, derby, postgres, oracle or mssql
-initSchema Creates the metastore tables for the current Hive version
-info Reports the schema version recorded in the database
-upgradeSchema Migrates an existing schema after a Hive upgrade
-validate Checks the schema for missing tables and version mismatches

One related property is worth knowing before the first start. When hive.metastore.schema.verification is true, Hive compares the schema version in MySQL against its own and refuses to run on a mismatch. That check is a safeguard, so the correct response is to run the upgrade rather than to switch it off. The same MySQL backend is used by the Hive installation covered in install Hive on Ubuntu.

Common Hive Metastore Errors and How to Fix Them

Most failures at this stage produce one of a handful of messages, and each points at a specific step above rather than at Hive itself.

Symptom Cause and fix
Version information not found in metastore The schema was never created. Run schematool with -initSchema against the same database named in the connection URL
ClassNotFoundException for the JDBC driver The connector JAR is missing from the Hive lib directory, or Connector/J 8 is in use and the class is now com.mysql.cj.jdbc.Driver. Recheck the soft link from Step 3
Access denied for user hiveuser Privileges were granted to one host only. Create the account for both localhost and the wildcard host, then run flush privileges
Syntax error near IDENTIFIED BY MySQL 8 removed IDENTIFIED BY from the GRANT statement. Issue CREATE USER first and GRANT afterwards
Public key retrieval is not allowed Connector/J 8 refuses an unencrypted handshake by default. Add useSSL=false and allowPublicKeyRetrieval=true to the JDBC URL on a trusted network
Tables are missing after a Hive upgrade The schema still matches the old version. Run schematool with -upgradeSchema instead of disabling schema verification

Once the metastore answers reliably, the table definitions it records are created with the statements described in Hive create, alter and drop table.

FAQs

Hive ships support for Derby, MySQL, PostgreSQL, Oracle and Microsoft SQL Server, and schematool accepts each of them through the -dbType flag. Derby remains the default and stays limited to a single session.

Embedded runs Derby inside the Hive process. Local runs the metastore code inside Hive but against an external database such as MySQL. Remote runs the metastore as its own Thrift service that several clients share.

DBS records databases, TBLS records tables, COLUMNS_V2 records column definitions, SDS records storage descriptors and PARTITIONS records partition entries. These names are internal, so query them for inspection rather than editing them by hand.

Store it in a Hadoop credential provider keystore and point hive.metastore.credential.provider.path at that file, then remove the plain value. Restricting file permissions on hive-site.xml is the minimum fallback.

The files on HDFS survive, but every table, partition and column definition disappears and Hive can no longer read them. Regular MySQL dumps of the metastore database are therefore part of normal cluster backup.

The Thrift metastore service listens on port 9083 by default, set through hive.metastore.port. Clients reach it with hive.metastore.uris rather than with direct JDBC credentials, which keeps the database password off client machines.

Yes. Anomaly detection over metastore query logs flags sudden call spikes, slow partition listings and runaway table growth before jobs time out. The model highlights candidates, and an administrator still confirms the cause.

Copilot drafts the javax.jdo.option property block from a short comment, and agentic assistants can script the whole setup. Verify the driver class and the port, because training data still favours the older connector name.

Summarize this post with: