Hive使用MySQL儲存Metastore

來源:互聯網
上載者:User

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添加使用者

mysql> CREATE USER 'hive'@'%' IDENTIFIED BY 'hivepasswd';
mysql> GRANT ALL PRIVILEGES ON *.* TO 'hive'@'%' WITH GRANT OPTION; 
2.修改設定檔conf/hive-default.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://localhost: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包
wget http://dev.mysql.com/get/Downloads/Connector-J/mysql-connector-java-5.1.11.tar.gz/from/http://mysql.he.net/
tar -xvzf mysql-connector-java-5.1.11.tar.gz
cp mysql-connector-java-5.1.11/*.jar /data/soft/hive/lib

4.啟動hive
bin/hive
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.
這個問題是因為hive對mysql的UTF-8編碼方式有限制,修改一下mysql的編碼方式即可:alter database name character set latin1;

FAILED: Error in metadata: javax.jdo.JDOException: Couldnt obtain a new sequence (unique id) : Binary logging not possible. Message: Transaction level 'READ-COMMITTED' in InnoDB is not safe for binlog mode 'STATEMENT'

因為,READ-COMMITTED需要把bin-log以mixed方式來記錄,用以下命令來修改:

set global binlog_format='MIXED';

相關文章

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.