hadoop中hive配置mysql


1.首先下載hive

下載地址   選擇帶有 bin 選項的  ,不然以后還要自己編譯

解壓安裝 移動到/usr/local/hive  下

進入hive目錄,進入conf

cp hive-env.sh.template hive-env.sh
cp hive-default.xml.template hive-site.xml
cp hive-log4j2.properties.template  hive-log4j2.properties
cp hive-exec-log4j.properties.template hive-exec-log4j.properties

  配置 hive/conf/hive-env.sh,把下面三項的注釋去掉並加上地址

HADOOP_HOME=/usr/local/hadoop

 export HIVE_CONF_DIR=/usr/local/hive/conf

 export HIVE_AUX_JARS_PATH=/usr/local/hive

 配置 hive/conf/hive-site.xml 

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<?xml-stylesheet type="text/xsl" href="configuration.xsl"?><!--
   Licensed to the Apache Software Foundation (ASF) under one or more
   contributor license agreements.  See the NOTICE file distributed with
   this work for additional information regarding copyright ownership.
   The ASF licenses this file to You under the Apache License, Version 2.0
   (the "License"); you may not use this file except in compliance with
   the License.  You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.
-->
<configuration>
<!--<property>
<name>hive.metastore.warehouse.dir</name>
<value>/user/hive/warehouse</value>
</property>
<property> 
<name>hive.metastore.local</name>
<value>true</value>
</property> -->
 <!-- 如果是遠程mysql數據庫的話需要在這里寫入遠程的IP或hosts -->
<property>
<name>javax.jdo.option.ConnectionURL</name>
<value>jdbc:mysql://localhost/hive?createDatabaseIfNotExist=true</value>
</property>
<property>
<name>javax.jdo.option.ConnectionDriverName</name>
<value>com.mysql.jdbc.Driver</value>
</property>
<property>
<name>javax.jdo.option.ConnectionUserName</name>
<value>root</value>
</property>
<property>
<name>javax.jdo.option.ConnectionPassword</name>
<value>root</value>
</property>

<property>  
   <name>hive.metastore.schema.verification</name>  
   <value>false</value>  
 </property>


<property>  
        <name>datanucleus.readOnlyDatastore</name>  
        <value>false</value>  
    </property>  
    <property>   
        <name>datanucleus.fixedDatastore</name>  
        <value>false</value>   
    </property>  
  
    <property>   
        <name>datanucleus.autoCreateSchema</name>   
        <value>true</value>   
    </property>  
      
    <property>  
        <name>datanucleus.autoCreateTables</name>  
        <value>true</value>  
    </property>  
  
    <property>  
        <name>datanucleus.autoCreateColumns</name>  
        <value>true</value>  
    </property>     
</configuration>

  配置 hive/bin/hive-config.sh  在最后添加

export JAVA_HOME=/usr/local/java
export HIVE_HOME=/usr/local/hive
export HADOOP_HOME=/usr/local/hadoop

  需要注意的是 hive使用mysql的時候需要把mysql 的jdbc包拷貝到hive/lib下,mysql包下載鏈接https://www.mysql.com/products/connector/

  啟動 mysql 服務

  service mysqld start

 使用 mysql -uroot  登陸測試是否成功,如果成功修改root密碼:

mysql>use mysql;
mysql> update user set password=passworD("test") where user='root';
mysql> flush privileges;
mysql> exit;  

 在先啟動hadoop服務下,在其中hive:

 啟動hive服務:

hive --service metastore& 

 啟動hive服務在后台運行:

hive --service hiveserver2  &

 接着啟動 hive客戶端:

hive

  如果進入 hive>  shell中證明起啟動成功;

  首先創建表:

hive> CREATE EXTERNAL TABLE MYTEST(num INT, name STRING)  
    > ROW FORMAT DELIMITED FIELDS TERMINATED BY '\t'    //分隔符 ‘\t’
    > ;

  導入數據:

hive> load data local inpath  '/tmp/hive.txt' overwrite into table MYTEST;  
Copying data from file:/tmp/hive.txt
Copying file: file:/tmp/hive.txt
Loading data to table default.mytest
Deleted hdfs://localhost:9000/user/hive/warehouse/mytest
OK
Time taken: 0.402 seconds

  查看數據:

hive> SELECT * FROM MYTEST;
OK
NULL    NULL
22    world
33    hive
Time taken: 0.089 seconds
hive> 

 最后看看/tmp/hive.txt 文檔:

sina@ubuntu:~/hive/conf$ cat /tmp/hive.txt 
11,hello
22    world
33    hive
sina@ubuntu:~/hive/conf$ 

  

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM