search
HomeDatabaseMysql TutorialHive集成Mysql作为元数据

Hive集成Mysql作为元数据

Jun 07, 2016 pm 03:34 PM
hivemysqlcasedataintegrateddefault

默认情况下,Hive元数据保存在内嵌的 Derby 数据库中,只能允许一个会话连接,只适合简单的测试。为了支持多用户多会话,则需要一个独立的元数据库,我们使用 MySQL 作为元数据库,Hive 内部对 MySQL 提供了很好的支持,配置一个独立的元数据库需要增加以下

默认情况下,Hive元数据保存在内嵌的 Derby 数据库中,只能允许一个会话连接,只适合简单的测试。为了支持多用户多会话,则需要一个独立的元数据库,我们使用 MySQL 作为元数据库,Hive 内部对 MySQL 提供了很好的支持,配置一个独立的元数据库需要增加以下几步骤:

第一步:安装MySQL服务器端和MySQL客户端,并启动MySQL服务。
此步省略,具体请看http://www.cnblogs.com/linjiqin/archive/2013/03/04/2942497.html

第二步:安装Hive
此步省略,具体请看http://www.cnblogs.com/linjiqin/archive/2013/03/04/2942402.html

第三步:为Hive建立相应的MySQL账户,并赋予足够的权限,执行命令如下:

hadoop@ubuntu:~$ mysql -uroot -pmysql
mysql> CREATE USER <span>'</span><span>hive</span><span>'</span> IDENTIFIED BY <span>'</span><span>mysql</span><span>'</span>;
mysql> GRANT ALL PRIVILEGES ON *.* TO <span>'</span><span>hive</span><span>'</span>@<span>'</span><span>%</span><span>'</span> WITH GRANT OPTION;
mysql> flush privileges;

默认情况下Mysql只允许本地登录,所以需要修改配置文件将地址绑定给注释掉:

root@ubuntu:~# <span>sudo</span> gedit /etc/mysql/my.cnf

找到如下内容:

# Instead of skip-networking the default is now to listen only on
# localhost which is more compatible and is not less secure.
#bind-address           = 127.0.0.1  <span><span>---</span><span>注释掉这一行就可以远程登录了</span></span>

重启mysql服务:

<span>sudo</span> service mysql restart

第四步:建立 Hive 专用的元数据库,记得创建时用刚才创建的“hive”账号登陆。

mysql> exit;
hadoop@ubuntu:~$ mysql -uhive -pmysql
mysql> create database hive;

第五步:在Hive的conf目录下的文件“hive-site.xml”中增加如下配置:

Hive集成Mysql作为元数据

<span></span><span>xml version="1.0"</span><span>?></span>
<span></span><span>xml-stylesheet type="text/xsl" href="configuration.xsl"</span><span>?></span>

<span><span>configuration</span><span>></span>
    <span><span>property</span><span>></span>
        <span><span>name</span><span>></span>hive.metastore.local<span></span><span>name</span><span>></span>
        <span><span>value</span><span>></span>true<span></span><span>value</span><span>></span>
    <span></span><span>property</span><span>></span>
    <span><span>property</span><span>></span>
        <span><span>name</span><span>></span>javax.jdo.option.ConnectionURL<span></span><span>name</span><span>></span>
        <span><span>value</span><span>></span>jdbc:mysql://192.168.11.157:3306/hive?characterEncoding=UTF-8<span></span><span>value</span><span>></span>
    <span></span><span>property</span><span>></span>
    <span><span>property</span><span>></span>
        <span><span>name</span><span>></span>javax.jdo.option.ConnectionDriverName<span></span><span>name</span><span>></span>
        <span><span>value</span><span>></span>com.mysql.jdbc.Driver<span></span><span>value</span><span>></span>
    <span></span><span>property</span><span>></span>
    <span><span>property</span><span>></span>
        <span><span>name</span><span>></span>javax.jdo.option.ConnectionUserName<span></span><span>name</span><span>></span>
        <span><span>value</span><span>></span>hive<span></span><span>value</span><span>></span>
    <span></span><span>property</span><span>></span>
    <span><span>property</span><span>></span>
        <span><span>name</span><span>></span>javax.jdo.option.ConnectionPassword<span></span><span>name</span><span>></span>
        <span><span>value</span><span>></span>mysql<span></span><span>value</span><span>></span>
    <span></span><span>property</span><span>></span>
<span></span><span>configuration</span><span>></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span>

Hive集成Mysql作为元数据

从前面我们知道我们的“hive-site.xml”是一个“hive-default.xml.template”的一个拷贝,里面的配置参数非常之多,但是并不是我们都需要的,我们知道,Hive 系统会加载两个配置文件一个默认配置文件“hive-default.xml”,另一个就是用户自定义文件“hive-site.xml”。当“hive-site.xml”中的配置参数的值与“hive-default.xml”文件中不一致时,以用户自定义的为准。所以我们就把我们不需要的参数都删除掉,只留下上面所示的内容。
备注:其实修改这里的配置文件如果在Linux下面进行则非常麻烦,尽然我们都建立了FTP了,为何不用,所以把Master.Hadoop上面的这个配置文件下载下来,按照要求进行修改,这样的文件在Windows进行操作是非常方便的,弄好之后在上传上去,覆盖原来的即可。

第六步:把MySQL的JDBC驱动包复制到Hive的lib目录下。
JDBC驱动包的版本:mysql-connector-java-5.1.18-bin.jar

第七步:启动 Hive Shell, 执行“show tables;”命令,如果不报错,表明基于独立元数据库的 Hive 已经安装成功了。

Hive集成Mysql作为元数据

hadoop@ubuntu:~$ hive
Logging initialized using configuration <span>in</span> <span>file</span>:/home/hadoop/hive-<span>0.9</span>.<span>0</span>/conf/hive-log4j.properties
Hive history <span>file</span>=/tmp/hadoop/hive_job_log_hadoop_201303041631_450140463.txt
hive> show tables;
OK
Time taken: <span>1.988</span> seconds
hive> 

Hive集成Mysql作为元数据

第八步:验证Hive配置是否有误,进入Hive的shell新建表,在MySQL的Hive数据库中可以看到相应的元数据库信息。
1)在Hive上建立数据表
hive> CREATE TABLE xp(id INT,name string) ROW FORMAT DELIMITED FIELDS TERMINATED BY '\t';
2)从 MySQL 数据库上查看元数据信息
用到的 SQL 语句:
use hive; //使用 hive 数据库库
show tables;//显示 hive 数据库中的数据表
select * from TBLS;//查看 hive 的元数据信息
到此Hive集成Mysql作为元数据已完成。

远程模式安装
远程模式安装是把 metastore 配置到远程机器上,可以配置多个。在独立模式的基础上需要在 hive-site.xml 文件中增加的配置项如下:

Hive集成Mysql作为元数据

<span><span>property</span><span>></span>
    <span><span>name</span><span>></span>hive.metastore.local<span></span><span>name</span><span>></span>
    <span><span>value</span><span>></span>local<span></span><span>value</span><span>></span>
<span></span><span>property</span><span>></span>
<span><span>property</span><span>></span>
    <span><span>name</span><span>></span>hive.metastore.uris<span></span><span>name</span><span>></span>
    <span><span>value</span><span>></span>uri1,uri2,... <span></span><span>value</span><span>></span>//可配置多个 uri
    <span><span>description</span><span>></span>JDBC connect string for a JDBC metastore<span></span><span>description</span><span>></span>
<span></span><span>property</span><span>></span></span></span></span></span></span></span></span>
Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Adding Users to MySQL: The Complete TutorialAdding Users to MySQL: The Complete TutorialMay 12, 2025 am 12:14 AM

Mastering the method of adding MySQL users is crucial for database administrators and developers because it ensures the security and access control of the database. 1) Create a new user using the CREATEUSER command, 2) Assign permissions through the GRANT command, 3) Use FLUSHPRIVILEGES to ensure permissions take effect, 4) Regularly audit and clean user accounts to maintain performance and security.

Mastering MySQL String Data Types: VARCHAR vs. TEXT vs. CHARMastering MySQL String Data Types: VARCHAR vs. TEXT vs. CHARMay 12, 2025 am 12:12 AM

ChooseCHARforfixed-lengthdata,VARCHARforvariable-lengthdata,andTEXTforlargetextfields.1)CHARisefficientforconsistent-lengthdatalikecodes.2)VARCHARsuitsvariable-lengthdatalikenames,balancingflexibilityandperformance.3)TEXTisidealforlargetextslikeartic

MySQL: String Data Types and Indexing: Best PracticesMySQL: String Data Types and Indexing: Best PracticesMay 12, 2025 am 12:11 AM

Best practices for handling string data types and indexes in MySQL include: 1) Selecting the appropriate string type, such as CHAR for fixed length, VARCHAR for variable length, and TEXT for large text; 2) Be cautious in indexing, avoid over-indexing, and create indexes for common queries; 3) Use prefix indexes and full-text indexes to optimize long string searches; 4) Regularly monitor and optimize indexes to keep indexes small and efficient. Through these methods, we can balance read and write performance and improve database efficiency.

MySQL: How to Add a User RemotelyMySQL: How to Add a User RemotelyMay 12, 2025 am 12:10 AM

ToaddauserremotelytoMySQL,followthesesteps:1)ConnecttoMySQLasroot,2)Createanewuserwithremoteaccess,3)Grantnecessaryprivileges,and4)Flushprivileges.BecautiousofsecurityrisksbylimitingprivilegesandaccesstospecificIPs,ensuringstrongpasswords,andmonitori

The Ultimate Guide to MySQL String Data Types: Efficient Data StorageThe Ultimate Guide to MySQL String Data Types: Efficient Data StorageMay 12, 2025 am 12:05 AM

TostorestringsefficientlyinMySQL,choosetherightdatatypebasedonyourneeds:1)UseCHARforfixed-lengthstringslikecountrycodes.2)UseVARCHARforvariable-lengthstringslikenames.3)UseTEXTforlong-formtextcontent.4)UseBLOBforbinarydatalikeimages.Considerstorageov

MySQL BLOB vs. TEXT: Choosing the Right Data Type for Large ObjectsMySQL BLOB vs. TEXT: Choosing the Right Data Type for Large ObjectsMay 11, 2025 am 12:13 AM

When selecting MySQL's BLOB and TEXT data types, BLOB is suitable for storing binary data, and TEXT is suitable for storing text data. 1) BLOB is suitable for binary data such as pictures and audio, 2) TEXT is suitable for text data such as articles and comments. When choosing, data properties and performance optimization must be considered.

MySQL: Should I use root user for my product?MySQL: Should I use root user for my product?May 11, 2025 am 12:11 AM

No,youshouldnotusetherootuserinMySQLforyourproduct.Instead,createspecificuserswithlimitedprivilegestoenhancesecurityandperformance:1)Createanewuserwithastrongpassword,2)Grantonlynecessarypermissionstothisuser,3)Regularlyreviewandupdateuserpermissions

MySQL String Data Types Explained: Choosing the Right Type for Your DataMySQL String Data Types Explained: Choosing the Right Type for Your DataMay 11, 2025 am 12:10 AM

MySQLstringdatatypesshouldbechosenbasedondatacharacteristicsandusecases:1)UseCHARforfixed-lengthstringslikecountrycodes.2)UseVARCHARforvariable-lengthstringslikenames.3)UseBINARYorVARBINARYforbinarydatalikecryptographickeys.4)UseBLOBorTEXTforlargeuns

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft