文章目录
一、内嵌模式(使用较少)
1、上传、解压、重命名
2、配置环境变量
export HIVE_HOME=/opt/installs/hive
export PATH=
H
I
V
E
H
O
M
E
/
b
i
n
:
HIVE_HOME/bin:
HIVEHOME/bin:PATH
3、配置conf下的hive-env.sh
cd /opt/installs/hive/conf
# 1.复制改名:cp hive-env.sh.template hive-env.sh
# 2.并修改:exportHIVE_CONF_DIR=/opt/installs/hive/conf
exportJAVA_HOME=/opt/installs/jdk
exportHADOOP_HOME=/opt/installs/hadoop
exportHIVE_AUX_JARS_PATH=/opt/installs/hive/lib
4、修改conf下的hive-site.xml
cd /opt/installs/hive/conf
# 1.复制改名:cp hive-default.xml.template hive-site.xml
# 2.并修改:
把Hive-site.xml 中所有包含${system:java.io.tmpdir}替换成/opt/installs/hive/tmp
把Hive-site.xml 中所有包含${system:user.name}替换成当前用户名root
5、启动hadoop集群
start-all.sh
6、给hdfs创建文件夹
# 1.创建:
hdfs dfs -mkdir-p /user/hive/warehouse
hdfs dfs -mkdir-p /tmp/hive/
# 2.赋权:
hdfs dfs -chmod750 /user/hive/warehouse
hdfs dfs -chmod777 /tmp/hive
7、修改hive-site.xml中的非法字符
在hive-site.xml中,3211行,96列的地方有一个非法字符,删除即可
8、初始化元数据
因为是内嵌模式,所以使用的数据库是derby:
schematool --initSchema-dbType derby
9、测试是否成功
输入hive 进入后,可以编写sql
10、内嵌模式的缺点
假如有一个窗口在使用你的hive,另一个窗口能进入,但是执行sql语句时会报错!
二、本地模式(最常用)
1、检查mysql是否正常
systemctl status mysqld
2、上传、解压、重命名
3、配置环境变量
# 1.编辑vim /etc/profile:
exportHIVE_HOME=/opt/installs/hive
exportPATH=$HIVE_HOME/bin:$PATH# 2.刷新:source /etc/profile
4、修改conf下的hive-env.sh
cd /opt/installs/hive/conf
# 1.重命名:mv hive-env.sh.template hive-env.sh
# 2.并添加:exportHIVE_CONF_DIR=/opt/installs/hive/conf
exportJAVA_HOME=/opt/installs/jdk
exportHADOOP_HOME=/opt/installs/hadoop
exportHIVE_AUX_JARS_PATH=/opt/installs/hive/lib
5、修改conf下的hive-site.xml
cd /opt/installs/hive/conf
# 1.重命名:mv hive-default.xml.template hive-site.xml
# 2.修改(将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><!--配置MySql的连接字符串--><property><name>javax.jdo.option.ConnectionURL</name><value>jdbc:mysql://localhost:3306/hive?createDatabaseIfNotExist=true</value></property><!--配置MySql的连接驱动--><property><name>javax.jdo.option.ConnectionDriverName</name><value>com.mysql.cj.jdbc.Driver</value></property><!--配置登录MySql的用户--><property><name>javax.jdo.option.ConnectionUserName</name><value>root</value></property><!--配置登录MySql的密码--><property><name>javax.jdo.option.ConnectionPassword</name><value>123456</value></property><!-- 以下两个不需要修改,只需要了解即可 --><!-- 该参数主要指定Hive的数据存储目录 --><property><name>hive.metastore.warehouse.dir</name><value>/user/hive/warehouse</value></property><!-- 该参数主要指定Hive的临时文件存储目录 --><property><name>hive.exec.scratchdir</name><value>/tmp/hive</value></property></configuration>
6、启动hadoop集群
start-all.sh
7、给hdfs创建文件夹
# 1.创建:
hdfs dfs -mkdir-p /user/hive/warehouse
hdfs dfs -mkdir-p /tmp/hive/
# 2.赋权:
hdfs dfs -chmod750 /user/hive/warehouse
hdfs dfs -chmod777 /tmp/hive
8、将mysql的驱动包,上传至 hive 的lib 文件夹下
mysql-connector-java-xxxx-jar
9、初始化元数据
schematool --initSchema-dbType mysql
10、测试
输入hive 进入后,可以编写sql
-- 创建表的时候,string类型不需要指定字符长度createtable`user`(id int,name string);-- 创建表的时候,varchar类型需要指定字符长度,否则报错!createtable`user`(id int,name varchar(20));-- insert 语句 走MR任务 比较慢insertinto`user`values(1,'wangcai');-- 包含*的全表查询和包含*的limit查询,不走MR任务select*from`user`;select*from`user`limit10;
版权归原作者 lzhlizihang 所有, 如有侵权,请联系我们删除。