hive 與mysql整合安裝

來源:互聯網
上載者:User

標籤:

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賬戶,並賦予足夠的許可權,執行命令如下:

[email protected]:~$ mysql -uroot -pmysql
mysql> CREATE USER ‘hive‘ IDENTIFIED BY ‘hive‘; 
mysql> GRANT ALL PRIVILEGES ON *.* TO ‘hive‘@‘%‘ WITH GRANT OPTION; 
mysql> flush privileges;重啟mysql服務: sudo service mysql restart

第四步:建立 Hive 專用的中繼資料庫,記得建立時用剛才建立的“hive”帳號登陸。

mysql> create database hive;

第五步:在Hive的conf目錄下的檔案“hive-site.xml”中增加如下配置:


cd $HIVE_HOME/conf
cp hive-default.xml.template hive-default.xml
cp hive-default.xml.template hive-site.xml 

 

從前面我們知道我們的“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進行操作是非常方便的,弄好之後在上傳上 去,覆蓋原來的即可。

所以在此可將hive-site.xml中


<configuration>內容清空
</configuration>

 

 

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

<configuration>
    <property>
        <name>hive.metastore.local</name>
        <value>true</value>
    </property>
    <property>
        <name>javax.jdo.option.ConnectionURL</name>
        <value>jdbc:mysql://192.168.1.78:3306/hive?characterEncoding=UTF-8</value>
    </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>hive</value>
    </property>
</configuration>

 將hive配置到etc/profile中 將$HIVE_HOME/bin配置到PATH中方便使用

將mysql-connector-java-5.1.32.jar拷貝到$HIVE_HOME/lib即可

 在bash中執行hive

 

執行hive遇到一堆問題

 

Terminal initialization failed; falling back to unsupported

 

 

java.lang.IncompatibleClassChangeError: Found class jline.Terminal, but interface was expected
    at jline.TerminalFactory.create(TerminalFactory.java:101)
    at jline.TerminalFactory.get(TerminalFactory.java:158)
    at jline.console.ConsoleReader.<init>(ConsoleReader.java:229)
    at jline.console.ConsoleReader.<init>(ConsoleReader.java:221)
    at jline.console.ConsoleReader.<init>(ConsoleReader.java:209)
    at org.apache.hadoop.hive.cli.CliDriver.getConsoleReader(CliDriver.java:773)
    at org.apache.hadoop.hive.cli.CliDriver.executeDriver(CliDriver.java:715)
    at org.apache.hadoop.hive.cli.CliDriver.run(CliDriver.java:675)
    at org.apache.hadoop.hive.cli.CliDriver.main(CliDriver.java:615)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at org.apache.hadoop.util.RunJar.run(RunJar.java:221)
    at org.apache.hadoop.util.RunJar.main(RunJar.java:136)

Exception in thread "main" java.lang.IncompatibleClassChangeError: Found class jline.Terminal, but interface was expected
    at jline.console.ConsoleReader.<init>(ConsoleReader.java:230)
    at jline.console.ConsoleReader.<init>(ConsoleReader.java:221)
    at jline.console.ConsoleReader.<init>(ConsoleReader.java:209)
    at org.apache.hadoop.hive.cli.CliDriver.getConsoleReader(CliDriver.java:773)
    at org.apache.hadoop.hive.cli.CliDriver.executeDriver(CliDriver.java:715)
    at org.apache.hadoop.hive.cli.CliDriver.run(CliDriver.java:675)
    at org.apache.hadoop.hive.cli.CliDriver.main(CliDriver.java:615)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at org.apache.hadoop.util.RunJar.run(RunJar.java:221)
    at org.apache.hadoop.util.RunJar.main(RunJar.java:136)

 

 解決方案:在/etc/profile中添加

 

export HADOOP_USER_CLASSPATH_FIRST=true

 

 

FAILED: Error in metadata: javax.jdo.JDOFatalDataStoreException: Access denied for user ‘hive‘@‘eidlink‘ (using password: YES)

NestedThrowables:

java.sql.SQLException: Access denied for user ‘hive‘@‘eidlink‘ (using password: YES)

FAILED: Execution Error, return code 1 from org.apache.hadoop.hive.ql.exec.DDLTask

解決方案:

 在bash中執行查看hostname 為eidlink

hostname

 登陸mysql

mysql -uhive -phive


mysql> grant all on hive.* to [email protected]‘eidlink‘ identified by ‘hive‘;
mysql>exit;
service mysql restart

執行hive 即可成功 hive預設啟動的記錄檔目錄為/tmp/登陸使用者/hive.log

 在192.168.1.78:3306/hive庫中將自動建立如下表

 

 

 

hive> show tables;
OK
Time taken: 1.279 seconds

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作為中繼資料已完成。 

 success!

hive 與mysql整合安裝

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.