Heim > Datenbank > MySQL-Tutorial > Hauptteil

Hive学习之配置MySQL为Metastore

WBOY
Freigeben: 2016-06-07 15:19:49
Original
1478 Leute haben es durchsucht

Hive默认情况下以内嵌模式使用Derby数据库做为metastore,该模式最大的缺陷是不支持多个客户端同时连接到metastore上,因此只适合用于学习测试的目的,要在实际生产上使用Hive需要将metastore配置为本地模式或者远程模式,现在就介绍如何以本地模式配置metas

   Hive默认情况下以内嵌模式使用Derby数据库做为metastore,该模式最大的缺陷是不支持多个客户端同时连接到metastore上,因此只适合用于学习测试的目的,要在实际生产上使用Hive需要将metastore配置为本地模式或者远程模式,现在就介绍如何以本地模式配置metastore,使用的数据库为MySQL5.6.19。在进行配置之前先要安装MySQL数据库,一般情况下Linux系统中已经安装了MySQL(至少我的系统中已经安装了),但往往数据库版本比较低,为了使用MySQL的最新版本需要先卸载之前的版本。可以使用下面的语句查询已经安装的MySQL:

rpm –qa | grep –i mysql
Nach dem Login kopieren

    然后根据查询结果使用下面的语句删除MySQL:

rpm -e xxxxx 或者
rpm -e --nodeps xxxxx
Nach dem Login kopieren

   卸载完成后,使用下面的语句安装MySQL的服务器:

[root@hadoophadoop]# rpm -ivh MySQL-server-5.6.19-1.el6.x86_64.rpm
Preparing...          ###################################[100%]
1:MySQL-server      ###################################[100%]
A RANDOMPASSWORD HAS BEEN SET FOR THE MySQL root USER !You will find that password in'/root/.mysql_secret'.Also, the account for the anonymous user has beenremoved.
##MySQL-5.6.19版本中会为root用户生成一个随机密码,并保存在/root/.mysql_secret中,在使用root用户首次登录时会用到该密码。
In addition, you can run:/usr/bin/mysql_secure_installation,which will also give you the option of removing the test database.This is strongly recommended for production servers.
##建议在生产中运行/usr/bin/mysql_secure_installation脚本,该脚本可以移除测试数据库,在生成环境中推荐该方式。
New default config file was created as /usr/my.cnf and will be used by default by the server when you start it.You may edit this file to change server settings
##新的配置文件保存在/usr/my.cnf
Nach dem Login kopieren

   安装MySQL客户端的语句及结果如下:

[root@hadoophadoop]# rpm -ivh MySQL-client-5.6.19-1.el6.x86_64.rpm
Preparing...           ###############################[100%]
1:MySQL-client       ################################ [100%]
Nach dem Login kopieren

   安装完MySQL后,运行下面的语句登录数据库,root用户的密码保存在/root/.mysql_secret中:

mysql –u root –p
Nach dem Login kopieren

   输入上述文件中的密码登录数据库,执行下面的语句,修改完root用户的密码后就可以在以后的登录中使用新密码。

mysql> use mysql
ERROR 1820(HY000): You must SET PASSWORD before executing this statement
mysql> set PASSWORD=PASSWORD('123456');
Query OK, 0 rowsaffected (0.12 sec)
Nach dem Login kopieren

   在完成了MySQL数据库的安装后,需要创建存储metastore的数据库,或者在连接时创建数据库。先创建数据库hive_db:

create database hive_db;
Nach dem Login kopieren

   然后创建metastore数据库的用户,并为该用户分配最大权限:

grant all privileges on hive_db.* to Hadoop identified by ‘hadoop’
Nach dem Login kopieren

   做完数据库的配置后,现在需要修改Hive的配置文件。将$HIVE_HOME/conf目录下的hive-default.xml.template复制为hive-site.xml:

cp hive-default.xml.template hive-site.xml
Nach dem Login kopieren

   然后修改下面的配置信息,指定使用MySQL做为存储metastore的数据库:

<property>
  <name>javax.jdo.option.ConnectionURL</name>
  <value>jdbc:mysql://Hadoop:3306/hive_db?createDatabaseIfNotExist=true</value>
  <description>JDBC connect string for aJDBC metastore</description>
</property>
<property>
 <name>javax.jdo.option.ConnectionDriverName</name>
  <value>com.mysql.jdbc.Driver</value>
  <description>Driver class name for aJDBC metastore</description>
</property>
<property>
 <name>javax.jdo.option.ConnectionUserName</name>
  <value>hadoop</value>
  <description>username to use againstmetastore database</description>
</property>
<property>
 <name>javax.jdo.option.ConnectionPassword</name>
  <value>hadoop</value>
  <description>password to use againstmetastore database</description>
</property>
Nach dem Login kopieren

   修改完配置文件后,将连接MySQL的驱动程序包放置到CLASSPATH中,可以放置到${HIVE_HOME}/lib下,然后成功启动Hive。

   使用hadoop用户登录到MySQL中,进入hive_db数据库,执行show tables语句,可以发现存在许多表,比如DBS、TBLS等,如下图所示:

Hive学习之配置MySQL为Metastore

   可以查询Hive中存在哪些数据库,如下所示:

Hive学习之配置MySQL为Metastore

   至此,配置MySQL以本地模式存储metastore已经完成,上面的图示也说明了这点。当然在实际执行过程中,也出现了一些问题,如没有将MySQL驱动程序加到CLASSPATH中,MySQL的安装问题,其中最大的问题不是来自Hive的,而是安装MySQL,这也说明在MySQL正常的情况下,配置其为metastore的数据库还是很简单的。

Verwandte Etiketten:
Quelle:php.cn
Erklärung dieser Website
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn
Beliebte Tutorials
Mehr>
Neueste Downloads
Mehr>
Web-Effekte
Quellcode der Website
Website-Materialien
Frontend-Vorlage
Über uns Haftungsausschluss Sitemap
Chinesische PHP-Website:Online-PHP-Schulung für das Gemeinwohl,Helfen Sie PHP-Lernenden, sich schnell weiterzuentwickeln!