Mac下Hive安裝和使用
阿新 • • 發佈:2019-02-04
1.Hive安裝
1.1下載
官網下載地址apache.fayea.com/hive/,目前最新版為1.2.2,選擇 apache-hive-1.2.2-bin.tar.gz檔案下載。
1.2 配置hive-env.sh
解壓檔案至本地資料夾,進入/conf資料夾,編輯hive-env.sh
# Set HADOOP_HOME to point to a specific hadoop install directory HADOOP_HOME=/Users/kk/hadoop/hadoop-2.6.5 # Hive Configuration Directory can be controlled by: export HIVE_CONF_DIR=/Users/kk/hadoop/hive-1.2.0/conf # Folder containing extra ibraries required for hive compilation/execution can be controlled by: export HIVE_AUX_JARS_PATH=/Users/kk/hadoop/hive-1.2.0/lib
HADOOP_HOME:Hadoop根目錄
HIVE_CONF_DIR:Hive配置資料夾
HIVE_AUX_JARS_PATH:Hive依賴jar包的路徑
1.3 配置hive-site.xml
編輯hive-site.xml檔案,修改以下引數
<property>
<name>hive.exec.scratchdir</name>
<value>/Users/kangkang/hadoop/warehouse</value>
<description>HDFS root scratch dir for Hive jobs which gets created with write all (733) permission. For each connecting user, an HDFS scratch dir: ${hive.exec.scratchdir}/<username> is created, with ${hive.scratch.dir.permission}.</description>
</property>
<property>
<name>hive.exec.local.scratchdir</name>
<value>/Users/kangkang/hadoop/hive-1.2 .0/tmp/${user.name}</value>
<description>Local scratch space for Hive jobs</description>
</property>
<property>
<name>hive.downloaded.resources.dir</name>
<value>/Users/kangkang/hadoop/hive-1.2.0/tmp/${hive.session.id}_resources</value>
<description>Temporary local directory for added resources in the remote file system.</description>
</property>
...
<property>
<name>hive.metastore.warehouse.dir</name>
<value>/Users/kangkang/hadoop/warehouse</value>
<description>location of default database for the warehouse</description>
</property>
...
<property>
<name>javax.jdo.option.ConnectionPassword</name>
<value>root</value>
<description>password to use against metastore database</description>
</property>
...
<property>
<name>hive.hwi.listen.port</name>
<value>9999</value>
<description>This is the port the Hive Web Interface will listen on</description>
</property>
...
<property>
<name>javax.jdo.option.ConnectionURL</name>
<value>jdbc:mysql://localhost:3306/hivedb?createDatabaseIfNotExist=true&useUnicode=true&characterEncoding=UTF-8&useSSL=false</value>
<description>JDBC connect string for a JDBC metastore</description>
</property>
...
<property>
<name>javax.jdo.option.ConnectionDriverName</name>
<value>com.mysql.jdbc.Driver</value>
<description>Driver class name for a JDBC metastore</description>
</property>
...
<property>
<name>hive.querylog.location</name>
<value>/Users/kangkang/hadoop/hive-1.2.0/tmp/${system:user.name}</value>
<description>Location of Hive run time structured log file</description>
</property>
...
1.4 新增依賴包
拷貝mysql的驅動jar包(mysql-connector-java-5.1.38.jar)到hive的/lib資料夾
拷貝/hive/lib/jline-2.12.jar 檔案拷貝至 /hadoop-2.6.5/share/hadoop/yarn/lib/下
建立一個快取資料夾/hive-1.2.2/tmp/
2.啟動Hive
在保證本機mysql服務開啟的情況下,啟動Hive命令:
bin/hive
bin/hiveserver2
注意:這裡是兩個服務同時啟動
hiveserver2是啟動服務,為jdbc的訪問提供服務。
3.Hive操作資料
建立表格:
create table table_name(id int primary key, name varchar);
刪除表格:
drop table table_name;
查詢
select * from table_name where id = 1;
Hive匯入檔案內容
load data local inpath '/Users/kk/dim_area.txt' into table dim_area;