一、Hive配置
前奏:
可以一个虚拟机中安装mysql 和 hive;
hive 最多应用于大数据的分析,,,因:长时间不连接会自动断开;
如果mysql 和 hive不在同一台虚拟机中,需要开启远程访问;
hive使hdfs存储的数据有结构。
在hive中建立一个库,等于在hdfs中创建一个目录。
hbase是以hadoop格式存储 只支持行级事务。
hive通过mapreduce进行检索作业 可以支持表级事务,但不支持多表;
hbase不通过mapreduce进行检索,有自己的套检索方式。
hive通常用于离线数据处理,所有处理速度比较慢。
1.首先在虚拟机中安装MySQL
2)上传到虚拟机中,并进行命令安装步骤: (ps:在root用户下操作)
①rpm -Uvh mysql57-community-release-el7-11.noarch.rpm
rpm:软件资源管理包
②yum repolist all | grep mysql 查看mysql版本
③yum -y install mysql-community-server 安装mysql
④systemctl start mysqld 开启mysql
⑤grep 'temporary password' /var/log/mysqld.log 查看初识密码(ps:12位)
mysql -uroot -p
⑥ALTER USER 'root'@'localhost' IDENTIFIED BY ’P@ssw0rd’; 修改密码:P@sswOrd
⑦mysql -uroot -pP@ssw0rd; 登录mysql
3)MySQL的其他操作:
systemctl status mysqld 查询mysql的状态
systemctl stop mysqld 停止mysql
rpm -qa | grep mysql 软件资源包管理器rpm
yum -y remove mysql 删除mysql
2.下载和安装Hive,并进行配置和运行
1)下载hive 地址 :apache.fayea.com/hive
①官网:hive.apache.org
2)上传并解压hive ,给解压文件改别名
解压:tar -zxvf apache-hive-2.3.0-bin.tar.gz
改别名:mv
apache-hive-2.3.0-bin hive (ps:目的在于启动hive时,直接输入hive回车)
3)对hive进行文件配置
[hadoop@hadoop-node2 conf]$ cat 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>
<!-- WARNING!!! This file is auto generated for documentation purposes ONLY! -->
<!-- WARNING!!! Any changes you make to this file will be ignored by Hive. -->
<!-- WARNING!!! You must make your changes in hive-site.xml instead. -->
<!-- Hive Execution Parameters -->
<property>
<name>hive.exec.local.scratchdir</name>
<value>/home/hadoop/hive/tmp/hive</value>
<description>Local scratch space for Hive jobs</description>
</property>
<property>
<name>hive.downloaded.resources.dir</name>
<value>/home/hadoop/hive/tmp/${hive.session.id}_resources</value>
<description>Temporary local directory for added resources in the remote file system.</description>
</property>
<property>
<name>hive.querylog.location</name>
<value>/home/hadoop/hive/tmp/hive</value>
<description>Location of Hive run time structured log file</description>
</property>
<property>
<name>hive.server2.logging.operation.log.location</name>
<value>/home/hadoop/hive/tmp/hive/operation_logs</value>
<description>Top level directory where operation logs are stored if logging functionality is enabled</description>
</property>
<property>
<name>hive.exec.scratchdir</name>
<value>/tmp/hive</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.scratch.dir.permission</name>
<value>700</value>
<description>The permission for the user specific scratch directories that get created.</description>
</property>
<property>
<name>javax.jdo.option.ConnectionPassword</name>
<value>P@ssw0rd</value>
<description>password to use against metastore database</description>
</property>
<property>
<name>javax.jdo.option.ConnectionURL</name>
<value>jdbc:mysql://localhost:3306/hive_metadata?createDatabaseIfNotExist=true&characterEncoding=utf8</value>
<description>
JDBC connect string for a JDBC metastore.
To use SSL to encrypt/authenticate the connection, provide database-specific SSL flag in the connection URL.
For example, jdbc:postgresql://myhost/db?ssl=true for postgres database.
</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>javax.jdo.option.ConnectionUserName</name>
<value>root</value>
<description>Username to use against metastore database</description>
</property>
<property>
<name>datanucleus.schema.autoCreateAll</name>
<value>true</value>
<description>Auto creates necessary schema on a startup if one doesn't exist. Set this to false, after creating it once.To enable auto create also set hive.metastore.schema.verification=false. Auto creation is not recommended for production use cases, run schematool command instead.</description>
</property>
<property>
<name>hive.metastore.schema.verification</name>
<value>false</value>
<description>
Enforce metastore schema version consistency.
True: Verify that version information stored in is compatible with one from Hive jars. Also disable automatic schema migration attempt. Users are required to manually migrate schema after Hive upgrade which ensures proper metastore schema migration. (Default) False: Warn if the version information stored in metastore doesn't match with one from in Hive jars.
</description>
</property>
</configuration>
⑤创建Hive的临时目录
4)启动运行
二、Hive之表操作
1.创建表(ps:都是在hive中进行的操作)
1)首先在hive中创建一个数据库:dsj101
2)使用命令:use dsj101 切换数据库
3)创建一个表:emp
4)导入数据:
5)查看导入到表emp中的数据:
2.DDL操作:
1)添加列
①先写一个文本文件:vi persons.txt
2)创建一个表:
3)Updata语法:
①编辑hive-site.xml文件:
<property>
<name>hive.optimize.sort.dynamic.partition</name>
<value>false</value>
</property>
<property>
<name>hive.support.concurrency</name>
<value>true</value>
</property>
<property>
<name>hive.enforce.bucketing</name>
<value>true</value>
</property>
<property>
<name>hive.exec.dynamic.partition.mode</name>
<value>nonstrict</value>
</property>
<property>
<name>hive.txn.manager</name>
<value>org.apache.hadoop.hive.ql.lockmgr.DbTxnManager</value>
</property>
<property>
<name>hive.compactor.initiator.on</name>
<value>true</value>
</property>
<property>
<name>hive.compactor.worker.threads</name>
<value>1</value>
</property>
<property>
<name>hive.in.test</name>
<value>true</value>
</property>
②
创表语句和要求:
3.查
4.更多内容请查看此链接:DDL & DDM
三、Hive帮助文档
1.帮助文档地址:
2.帮助文档路径:
1)地址栏中:hive.apache.org
2)
3)
4)
5)