hive使用mysql存储元数据

来源:互联网 发布:电脑网络节点 编辑:程序博客网 时间:2024/05/21 14:57
Hive 将元数据存储在 RDBMS 中,有三种模式可以连接到数据库: 
1)ingle User Mode: 此模式连接到一个 In-memory 的数据库 Derby,一般用于 Unit Test。 
2)Multi User Mode:通过网络连接到一个数据库中,是最经常使用到的模式。 
3)Remote Server Mode:用于非 Java 客户端访问元数据库,在服务器端启动一个 MetaStoreServer,客户端利用 Thrift 协议通过 MetaStoreServer 访问元数据库。 

Hive默认是采用Derby来存储其Meta信息的, 
现在我们需要修改为mysql 

1.在mysql专门为hive添加用户 
Java代码  收藏代码
  1. mysql> CREATE USER 'hive'@'hive-mysql' IDENTIFIED BY 'hivepasswd';  
  2. mysql> GRANT ALL PRIVILEGES ON *.* TO 'hive'@'hive-mysql' WITH GRANT OPTION;  


2.修改配置文件conf/hive-site.xml 
Xml代码  收藏代码
  1. <property>    
  2.         <name>hive.metastore.local</name>    
  3.         <value>true</value>    
  4.         <description>controls whether to connect to remove metastore server or open a new metastore server in Hive Client JVM</description>  
  5. </property>  
  6. <property>    
  7.         <name>javax.jdo.option.ConnectionURL</name>    
  8.         <value>jdbc:mysql://hive-mysql:3306/hive?createDatabaseIfNotExist=true</value>    
  9.         <description>JDBC connect string for a JDBC metastore</description>  
  10. </property>  
  11. <property>    
  12.         <name>javax.jdo.option.ConnectionDriverName</name>    
  13.         <value>com.mysql.jdbc.Driver</value>    
  14.         <description>Driver class name for a JDBC metastore</description>  
  15. </property>  
  16. <property>    
  17.         <name>javax.jdo.option.ConnectionUserName</name>    
  18.         <value>hive</value>    
  19.         <description>username to use against metastore database</description>  
  20. </property>  
  21. <property>    
  22.         <name>javax.jdo.option.ConnectionPassword</name>    
  23.         <value>hivepasswd</value>    
  24.         <description>password to use against metastore database</description>  
  25. </property>  


3.添加jdbc的jar包 
Java代码  收藏代码
  1. wget http://dev.mysql.com/get/Downloads/Connector-J/mysql-connector-java-5.1.11.tar.gz/from/http://mysql.he.net/  
  2. tar -xvzf mysql-connector-java-5.1.11.tar.gz  
  3. cp mysql-connector-java-5.1.11/*.jar /data/soft/hive/lib  


4.启动hive 
Java代码  收藏代码
  1. bin/hive  
  2. hive> show tables;  



When using MySQL as a metastore I see the error "com.mysql.jdbc.exceptions.MySQLSyntaxErrorException: Specified key was too long; max key length is 767 bytes". 

    * This is a known limitation of MySQL 5.0 and UTF8 databases. One option is to use another character set, such as 'latin1', which is known to work. 
原创粉丝点击