Hive is a data warehouse tool based on Hadoop for data extraction, transformation, and loading. This is a mechanism that can store, query, and analyze large-scale data stored in Hadoop. In this article, I will take you through how to Install Hive on Mac with Homebrew using Terminal.

Install Hive on Mac


The installation of Hadoop is divided into these steps:

  1. HDFS (Hadoop) setup : This step is need to completed first place before Hive installation. Please follow the steps to perform the installation.
  2. Hive Installation 
  3. Setup Hive & Mysql Environment Variables
  4. Setup Mysql / Derby database: Hive need this database (called Metastore)  to store the Hive metadata. 
  5. Download the MySQL driver package
  6. Hive  Configuration
  7. Initialize the metadata database
  8. Start Metastore service
  9. Run Hive

Install Hive 


Install Hive with below command

$ brew install hive

Setup Hive & Mysql Environment Variables


Enter vim ~/.bash_profile in the terminal to configure the hive path statement in the blank line.

## HIVE env variables
export HIVE_HOME=/usr/local/Cellar/hive/3.1.2_3/libexec
export PATH=$PATH:/$HIVE_HOME/bin

## MySQL ENV
export PATH=$PATH:/usr/local/mysql-8.0.12-macos10.13-x86_64/bin

Setup Mysql database


Download Mysql database by going to the following Mysql site. After installing the Mysql follow the next steps to initialize the metadata database.

Configuration

  1. Log in to Mysql: $ mysql -u root -p
  2. Create a database: CREATE database metastore;
  3. $ Source /usr/local/Cellar/hive/3.1.2_3/libexec/scripts/metastore/upgrade/mysql/hive-schema-3.1.0.mysql.sql
  4. CREATE a new user: $ CREATE user ‘hive’@’localhost’ identified by ‘password123’;
  5. Modify user permissions: $ GRANT ALL PRIVILEGES ON  *.* to ‘hive’@’localhost’;
  6. Refresh privileges: FLUSH PRIVILEGES;

Download the MySQL driver package


  1. Open the MySQL official websit
  2. Select Platform Independent -> Download to your machine
  3. Unzip -> Place the jar “mysql-connector-java-8.0.19.jar”  into the /usr/local/Cellar/hive/3.1.2_3/libexec/lib directory

Setup Hive Configuration


Create a file named “hive-site.xml” in the following locations /usr/local/Cellar/hive/3.1.2_3/libexec/conf directory. Please note this file does not exist and needs to be created manually.

<configuration>
<property>
<name>hive.querylog.location</name>
<value>/Users/apache-hive-3.1.2-bin/log/hive.log</value>
</property>
<property>
<name>hive.querylog.enable.plan.progress</name>
<value>false</value>
</property>
<property>
<name>hive.log.explain.output</name>
<value>false</value>
</property>
<property>
<name>javax.jdo.option.ConnectionURL</name>
<value>jdbc:mysql://localhost:3306/hive?createDatabaseIfNotExist=true</value>
</property>
<property>
<name>javax.jdo.option.ConnectionDriverName</name>
<value>com.mysql.cj.jdbc.Driver</value>
</property>
<property>
<name>javax.jdo.option.ConnectionUserName</name>
<value>hive</value>
</property>
<property>
<name>javax.jdo.option.ConnectionPassword</name>
<value>password123</value>
</property>
<property>
<name>hive.metastore.schema.verification</name>
<value>false</value>
</property>
<property>
<name>hive.metastore.warehouse.dir</name>
<value>hdfs://localhost:9000/user/hive/warehouse</value>
</property>
</configuration>

Initialize the metadata database


cd /usr/local/Cellar/hive/3.1.2_3/libexec/bin
schematool -initSchema -dbType mysql

Start Metastore service


./hive --service metastore &

Run Hive

Enter the hive command directly in the terminal

hive> show databases;
OK
default
Time taken: 0.248 seconds, Fetched: 2 row(s)