一、安装mysql
$ sudo apt-get install mysql-server
启动守护进程
$ sudo service mysql start
二、配置mysql服务与连接器
1、安装mysql连接器
$ sudo apt-get install libmysql-java
注:将/usr/share/java/下的连接器jar包copy到$HIVE_HOME/lib下
如图所示
2、设置mysql root密码
$ sudo /usr/bin/mysql_secure_installation
[...] Enter current password for root (enter for none):
OK, successfully used password, moving on...
[...] Set root password? [Y/n] y
New password:
Re-enter new password:
Remove anonymous users? [Y/n] Y
[...]
Disallow root login remotely? [Y/n] N
[...]
Remove test database and access to it [Y/n] Y
[...]
Reload privilege tables now? [Y/n] Y
All done!
三、创建数据库与用户
创建初始数据库模式。Cloudera的建议使用Hive schema tool来做到这一点。
如果不打算使用,可通过hive-schema-*.*.*.mysql.sql文件来代替,该文件位置: $HIVE_HOME/scripts/metastore/upgrade/mysql目录下
以hive-schema-1.2.0.mysql.sql为例
$ mysql -u root -p
Enter password:
mysql> CREATE DATABASE metastore;
mysql> USE metastore;
mysql> SOURCE $HIVE_HOME/scripts/metastore/upgrade/mysql/hive-schema-1.2.0.mysql.sql;
我们还需要为hive配置一个mysql账号用于访问该metastore。
例:
mysql> CREATE USER 'hive'@'localhost' IDENTIFIED BY 'password';
...
mysql> REVOKE ALL PRIVILEGES, GRANT OPTION FROM 'hive'@'localhost';
mysql> GRANT ALL PRIVILEGES ON metastore.* TO 'hive'@'localhost';
mysql> FLUSH PRIVILEGES;
mysql> quit;
注:如果mysql与hive安装在不同hostname下,如要将localhost换成hive所在的hostname
四、配置hive与mysql的通信
在$HIVE_HOME/conf下创建hive-site.xml,配置如下:
<property>
<name>javax.jdo.option.ConnectionURL</name>
<value>jdbc:mysql://127.0.0.1/metastore</value>
<description>the URL of the MySQL database</description>
</property>
<property>
<name>javax.jdo.option.ConnectionDriverName</name>
<value>com.mysql.jdbc.Driver</value>
</property>
<property>
<name>javax.jdo.option.ConnectionUserName</name>
<value>hive</value>
</property>
<property>
<name>javax.jdo.option.ConnectionPassword</name>
<value>password</value>
</property>
<property>
<name>datanucleus.autoCreateSchema</name>
<value>false</value>
</property>
<property>
<name>datanucleus.fixedDatastore</name>
<value>true</value>
</property>
<property>
<name>datanucleus.autoStartMechanism</name>
<value>SchemaTable</value>
</property>
<property>
<name>hive.metastore.uris</name>
<value>thrift://127.0.0.1:9083</value>
</property>
<property>
<name>hive.metastore.schema.verification</name>
<value>true</value>
</property>
在启动hive过程中如果出现以下错误,可通过删除$HADOOP_HOME/share/hadoop/yarn/lib/ 下的jline-0.9.94.jar文件,它与beeline的依赖产生冲突