当前位置:   article > 正文

Hive安装详细教程

hive安装

一.Hive安装
1、下载安装包:apache-hive-3.1.1-bin.tar.gz
上传至linux系统/opt/software路径
2、解压软件

cd /opt/software
tar -zxvf apache-hive-3.1.1-bin.tar.gz -C /opt/module/
  • 1
  • 2

3、修改系统环境变量

vi /etc/profile
  • 1

添加内容:

export HIVE_HOME=/opt/module/apache-hive-3.1.1-bin
export PATH=$PATH:$HADOOP_HOME/sbin:$HIVE_HOME/bin
  • 1
  • 2

保存:

source /etc/profile
  • 1

4、修改hive环境变量

cd  /opt/module/apache-hive-3.1.1-bin/bin/
  • 1

编辑hive-config.sh文件

vi hive-config.sh
  • 1

新增内容:

export JAVA_HOME=/opt/module/jdk1.8.0_11
export HIVE_HOME=/opt/module/apache-hive-3.1.1-bin
export HADOOP_HOME=/opt/module/hadoop-3.2.0
export HIVE_CONF_DIR=/opt/module/apache-hive-3.1.1-bin/conf
  • 1
  • 2
  • 3
  • 4

5、拷贝hive配置文件

cd /opt/module/apache-hive-3.1.1-bin/conf/
cp hive-default.xml.template hive-site.xml
  • 1
  • 2

6、修改Hive配置文件,找到对应的位置进行修改

 <property>
    <name>javax.jdo.option.ConnectionDriverName</name>
    <value>com.mysql.cj.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>javax.jdo.option.ConnectionPassword</name>
    <value>root123</value>
    <description>password to use against metastore database</description>
  </property>
<property>
    <name>javax.jdo.option.ConnectionURL</name>
<value>jdbc:mysql://192.168.202.131:3306/hive?useUnicode=true&amp;characterEncoding=utf8&amp;useSSL=false&amp;serverTimezone=GMT</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>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>
<property>
    <name>hive.exec.local.scratchdir</name>
    <value>/opt/module/apache-hive-3.1.1-bin/tmp/${user.name}</value>
    <description>Local scratch space for Hive jobs</description>
  </property>
  <property>
<name>system:java.io.tmpdir</name>
<value>/opt/module/apache-hive-3.1.1-bin/iotmp</value>
<description/>
</property>

  <property>
    <name>hive.downloaded.resources.dir</name>
<value>/opt/module/apache-hive-3.1.1-bin/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>/opt/module/apache-hive-3.1.1-bin/tmp/${system:user.name}</value>
    <description>Location of Hive run time structured log file</description>
  </property>
  <property>
    <name>hive.server2.logging.operation.log.location</name>
<value>/opt/module/apache-hive-3.1.1-bin/tmp/${system:user.name}/operation_logs</value>
    <description>Top level directory where operation logs are stored if logging functionality is enabled</description>
  </property>
  <property>
    <name>hive.metastore.db.type</name>
    <value>mysql</value>
    <description>
      Expects one of [derby, oracle, mysql, mssql, postgres].
      Type of database used by the metastore. Information schema &amp; JDBCStorageHandler depend on it.
    </description>
  </property>
  <property>
    <name>hive.cli.print.current.db</name>
    <value>true</value>
    <description>Whether to include the current database in the Hive prompt.</description>
  </property>
  <property>
    <name>hive.cli.print.header</name>
    <value>true</value>
    <description>Whether to print the names of the columns in query output.</description>
  </property>
  <property>
    <name>hive.metastore.warehouse.dir</name>
    <value>/user/hive/warehouse</value>
    <description>location of default database for the warehouse</description>
  </property>
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
  • 83
  • 84
  • 85
  • 86
  • 87
  • 88
  • 89

7、上传mysql驱动包到/usr/local/soft/apache-hive-3.1.1-bin/lib/文件夹下
驱动包:mysql-connector-java-8.0.15.zip,解压后从里面获取jar包
在这里插入图片描述

8、确保 mysql数据库中有名称为hive的数据库
9、初始化初始化元数据库

 schematool -dbType mysql -initSchema
  • 1

10、确保Hadoop启动
11、启动hive

hive
  • 1

12、检测是否启动成功

show databases;
  • 1

二.命令简单使用
(1)启动hive
[linux01 hive]$ bin/hive
(2)显示数据库
hive>show databases;
(3)使用default数据库
hive>use default;
(4)显示default数据库中的表
hive>show tables;
(5)创建student表, 并声明文件分隔符’\t’
hive> create table student(id int, name string) ROW FORMAT DELIMITED FIELDS TERMINATED BY ‘\t’;
(6)加载/usr/local/data/student.txt 文件到student数据库表中。
Linux创建students.txt文件编辑文件内容,将文件上传至hdfs中
hadoop fs - put /usr/local/data/student.txt /data

load data inpath ‘/data/student.txt’ overwrite into table student;
load data local inpath ‘/data/student.txt’ into table student;
(7)查询数据库
hive> select * from student;
查询id
hive> select id from student;
(8)退出hive窗口:
hive(default)>exit;
(9)在hive cli命令窗口中如何查看hdfs文件系统
hive(default)>dfs -ls /;

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/Monodyee/article/detail/384146
推荐阅读
  

闽ICP备14008679号