In this blog, We will see the installation of hive with mysql database.
Steps to Download and Configure MySql Metastore for Hive
Step 1: Download the Hive from it’s official website by clicking on this Link and download the tar file shown in the below image which is about 143MB in size.
tar -xvf apache-hive-2.1.1-bin.tar.gz
Step 2: Once you have downloaded the Hive now download the MySQL java connector from maven repository.
Step 3: Move to /lib folder inside your apache-hive-2.1.1-bin folder and then delete the file log4j-slf4j-impl-2.4.1.jar . We have deleted this file because the same file is also present in the Hadoop folder because of which sometimes it gives an error.
Step 7: Now we will install MySQL with below command.
sudo apt-get install mysql-server
Step 8: Create the Metastore Database after entering your MySQL terminal, implement all the below commands to do so (use root as password for SQL).
mysql> sudo mysql -u root -p
mysql> CREATE DATABASE metastore_db;
mysql> USE metastore_db;
Change the username according to you and path also if it is different. select metastore version .sql file based on hive version series
mysql> SOURCE /home/{user-name}/apache-hive-2.1.1-bin/scripts/metastore/upgrade/mysql/hive-schema-0.14.0.mysql.sql;
in my case hdoop is the username.
mysql> source /home/hdoop/apache-hive-2.1.1-bin/scripts/metastore/upgrade/mysql/hive-schema-0.14.0.mysql.sql
Step 9: Now make hive user and hive password with below command on mysql terminal.
mysql> create user 'hive'@'%' identified by 'hive';
Query OK, 0 rows affected (0.02 sec)
mysql> grant all PRIVILEGES on *.* to 'hive'@'%' with grant option;
Query OK, 0 rows affected (0.02 sec)
mysql> create user 'hdfs'@'%' identified by 'hdfs';
Query OK, 0 rows affected (0.04 sec)
mysql> grant all PRIVILEGES on *.* to 'hdfs'@'%' with grant option;
Query OK, 0 rows affected (0.03 sec)
mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.02 sec)
mysql> exit
Step 10: Now open hive-env.sh and append your hadoop path inside it.
export HADOOP_HOME=/home/hdoop/hadoop-3.2.1
Step 11: create a new file as hive-site.xml and enter the following content in the file
cd $HIVE_HOME/conf
vi hive-site.xml
<configuration> <property> <name>javax.jdo.option.ConnectionURL</name> <value>jdbc:mysql://localhost/metastore_db?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>hive</value> <description>user name for connecting to mysql server</description> </property> <property> <name>javax.jdo.option.ConnectionPassword</name> <value>hive</value> <description>hivepassword for connecting to mysql server</description> </property> <property> <name>hive.metastore.warehouse.dir</name> <value>/user/hive/warehouse</value> <description>location of default database for the warehouse</description> </property> <property> <name>hive.metastore.uris</name> <value>thrift://localhost:9083</value> <description>Thrift URI for the remote metastore.</description> </property> <property> <name>hive.server2.enable.doAs</name> <value>false</value> </property> </configuration>
Step 12: Starting Hive metastore…
Now let’s start our metastore service, run the following command in your terminal,
hive --service metastore
Open the hive console by hive command.
hive
Test the hive
If you were able to get into the hive console without any errors, you can verify your metastore configuration by following these steps.
hive
Create a table in hive.
create table test(id int, name string);