一、内嵌模式(使用较少)
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 ATH
3、配置conf下的hive-env.sh
- cd /opt/installs/hive/conf
- # 1.复制改名:
- cp hive-env.sh.template hive-env.sh
- # 2.并修改:
- export HIVE_CONF_DIR=/opt/installs/hive/conf
- export JAVA_HOME=/opt/installs/jdk
- export HADOOP_HOME=/opt/installs/hadoop
- export HIVE_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集群
6、给hdfs创建文件夹
- # 1.创建:
- hdfs dfs -mkdir -p /user/hive/warehouse
- hdfs dfs -mkdir -p /tmp/hive/
- # 2.赋权:
- hdfs dfs -chmod 750 /user/hive/warehouse
- hdfs dfs -chmod 777 /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是否正常
2、上传、解压、重命名
3、配置环境变量
- # 1.编辑
- vim /etc/profile:
- export HIVE_HOME=/opt/installs/hive
- export PATH=$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.并添加:
- export HIVE_CONF_DIR=/opt/installs/hive/conf
- export JAVA_HOME=/opt/installs/jdk
- export HADOOP_HOME=/opt/installs/hadoop
- export HIVE_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集群
7、给hdfs创建文件夹
- # 1.创建:
- hdfs dfs -mkdir -p /user/hive/warehouse
- hdfs dfs -mkdir -p /tmp/hive/
- # 2.赋权:
- hdfs dfs -chmod 750 /user/hive/warehouse
- hdfs dfs -chmod 777 /tmp/hive
复制代码 8、将mysql的驱动包,上传至 hive 的lib 文件夹下
mysql-connector-java-xxxx-jar
9、初始化元数据
- schematool --initSchema -dbType mysql
复制代码 10、测试
输入hive 进入后,可以编写sql
- -- 创建表的时候,string类型不需要指定字符长度
- create table `user` (id int,name string);
- -- 创建表的时候,varchar类型需要指定字符长度,否则报错!
- create table `user` (id int,name varchar(20));
- -- insert 语句 走MR任务 比较慢
- insert into `user` values(1,'wangcai');
- -- 包含*的全表查询和包含*的limit查询,不走MR任务
- select * from `user`;
- select * from `user` limit 10;
复制代码 免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。 |