Installing Hive in Mac

Apache Hive Installation

The default apache hive comes with a Derby Database that can support only one user at a time and resets itself every time  hive server is restarted. To avoid this, it becomes necessary to setup the mysql database server, connect the hive server to mysql db. The mysql will become the de facto for storing metadata for all hive databases and tables, that the hive creates. We need to ensure that the database (metastore) in mysql server will have the read/write access to the user so that the hive can make changes over time.

It is necessary that the following software has been installed in your Mac OS X (Lion/Yosemite)

  • Xcode (latest Version)
  • Hadoop 2.3+

If not, follow the instructions in Xcode link

Hadoop and Brew Installation

For instructions to setup hadoop, please refer to this link

For instructions to install brew, please refer to this link

Hive Installation

$ brew install hive
$ vi ~/.bash_profile
$ vi ~/.bash_profile
export HIVE_HOME=/usr/local/Cellar/hive/1.1.0
$ source ~/.bash_profile

Install mySQL Server

$ brew install mysql
$ mysql -u root

Error 1: Can’t connect to local MySQL server through socket ‘/tmp/mysql.sock’ (2)

$ brew uninstall mysql 
$ brew install mysql
$ mysql -u root

Setup mySQL server

Ensure that the username is the same as that of user for which hadoop and hive was installed.

mysql> CREATE DATABASE metastore;
mysql> USE metastore;
mysql> CREATE USER 'username'@'localhost' IDENTIFIED BY 'password';
mysql> GRANT SELECT,INSERT,UPDATE,DELETE,ALTER,CREATE, INDEX ON metastore.* TO 'username'@'localhost';
mysql> create database tempstatsstore;
mysql> GRANT SELECT,INSERT,UPDATE,DELETE,ALTER,CREATE, INDEX ON tempstatsstore.* TO 'username'@'localhost';

Error 2: The specified datastore driver (“com.mysql.jdbc.Driver”) was not found in the CLASSPATH.

Download the latest version of the mysql-connector-java using curl

curl -L 'http://www.mysql.com/get/Downloads/Connector-J/mysql-connector-java-5.1.35.tar.gz/from/http://mysql.he.net/' | tar xz

5.1.35 was the latest version of the JDBC mysql connector. We can check my visiting the mysql download website

$ cp mysql-connector-java-5.1.35/mysql-connector-java-5.1.35-bin.jar /usr/local/Cellar/hive/1.1.0/lib/

Just in case, we forget mysql root password, reset following instructions here.

Setup Hive Configuration

$ /usr/local/Cellar/hive/1.1.0/conf$ cp hive-default.xml.template hive-site.xml
 
 <property>
 <name>javax.jdo.option.ConnectionPassword</name>
 <value>password</value>
 <description>password to use against metastore database</description>
 </property>
 <property>
 <name>javax.jdo.option.ConnectionURL</name>
 <value>jdbc:mysql://localhost/metastore</value>
 <description>JDBC connect string for a JDBC metastore</description>
 </property>
 <property>
 <name>javax.jdo.option.ConnectionDriverName</name>
 <value>com.mysql.jdbc.Driver</value>
 <description>Driver class name for a JDBC metastore</description>
 </property>
 <property>
 <name>javax.jdo.option.ConnectionUserName</name>
 <value>username</value>
 <description>Username to use against metastore database</description>
 </property>

Other useful hive settings

 
 <property>
 <name>hive.cli.print.current.db</name>
 <value>true</value>
 <description>Whether to include the current database in the Hive prompt.</description>
 </property>
 <property>
 <name>hive.stats.jdbcdriver</name>
 <value>com.mysql.jdbc.Driver</value>
 <description>JDBC driver for the database that stores temporary Hive statistics.</description>
 </property>
 <property>
 <name>hive.stats.dbconnectionstring</name>
 <value>jdbc:mysql://localhost/tempstatsstore</value>
 <description>The default connection string for the database that stores temporary Hive statistics.</description>
 </property>
 <property>
 <name>hive.cli.print.header</name>
 <value>true</value>
 <description>Whether to print the names of the columns in query output.</description>
 </property>

2 thoughts on “Installing Hive in Mac

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s