2、Hive安裝

安裝

  1. 解壓hive
    tar -zxvf apache-hive-1.2.1-bin.tar.gz -C /opt/module/
  2. 重命名
    mv apache-hive-1.2.1-bin/ hive
  3. 復(fù)制配置文件
    cp hive-env.sh.template hive-env.sh
  4. 修改配置文件
    export HADOOP_HOME=/opt/module/hadoop-2.8.3
    export HIVE_CONF_DIR=/opt/module/hive/conf
  5. 配置環(huán)境變量
    # HIVE_HOME
    export HIVE_HOME=/opt/module/hive
    export PATH=$PATH:$HIVE_HOME/bin
  6. 啟動(dòng)hdfs和yarn
    start-dfs.sh
    start-yarn.sh
  7. 在HDFS上創(chuàng)建/tmp和/user/hive/warehouse兩個(gè)目錄并修改他們的同組權(quán)限可寫
    hadoop fs -mkdir /tmp
    hadoop fs -mkdir -p /user/hive/warehouse
    hadoop fs -chmod g+w /tmp
    hadoop fs -chmod g+w /user/hive/warehouse

基本操作

  1. 啟動(dòng)hive
    hive
  2. 查看數(shù)據(jù)庫
    show databases;
  3. 打開默認(rèn)數(shù)據(jù)庫
    use default;
  4. 顯示default數(shù)據(jù)庫中的表
    show tables;
  5. 創(chuàng)建一張表
    create table people(id int, name string);
  6. 顯示數(shù)據(jù)庫中有幾張表
    show tables;
  7. 查看表的結(jié)構(gòu)
    desc people;
  8. 向表中插入數(shù)據(jù)
    insert into people values(1,"ss");
  9. 查詢表中數(shù)據(jù)
    select * from people;
  10. 退出hive
    quit;

將本地文件導(dǎo)入hive操作

將本地/opt/module/datas/student.txt 這個(gè)文件的數(shù)據(jù)導(dǎo)入到hive的student(id int, name string)表中。
創(chuàng)建表
create table student(id int, name string) row format delimited fields terminated by '\t';
加載數(shù)據(jù)
load data local inpath '/opt/module/datas/student.txt' into table student;
查詢數(shù)據(jù)
select * from student;

Hive元數(shù)據(jù)配置到MySql

遇到的問題

Hive的Metastore默認(rèn)存儲(chǔ)在自帶的derby數(shù)據(jù)庫中,所以當(dāng)開多個(gè)客戶端啟動(dòng)hive,會(huì)有異常,如下


hive多窗口啟動(dòng)報(bào)錯(cuò).png

Hive元數(shù)據(jù)配置到MySql

  1. 復(fù)制驅(qū)動(dòng)到/opt/module/hibe/lib/
    cp mysql-connector-java-5.1.27-bin.jar /opt/module/hive/lib/
  2. 在/opt/module/hive/conf目錄下創(chuàng)建一個(gè)hive-site.xml
    touch hive-site.xml
  3. 復(fù)制下面內(nèi)容到hive-site.xml中
<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="configuration.xsl"?>
<configuration>
        <property>
          <name>javax.jdo.option.ConnectionURL</name>
          <value>jdbc:mysql://hadoop-100:3306/metastore?createDatabase
IfNotExist=true</value>
          <description>JDBC connect string for a JDBC metastore</descr
iption>
        </property>

        <property>
          <name>javax.jdo.option.ConnectionDriverName</name>
          <value>com.mysql.jdbc.Driver</value>
          <description>Driver class name for a JDBC metastore</descrip
tion>
        </property>

        <property>
          <name>javax.jdo.option.ConnectionUserName</name>
          <value>root</value>
          <description>username to use against metastore database</des
cription>
        </property>

        <property>
          <name>javax.jdo.option.ConnectionPassword</name>
          <value>root</value>
          <description>password to use against metastore database</des
cription>
        </property>
</configuration>
  1. 打開多個(gè)客戶端測試
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容