文章目录
1. 内嵌 Derby 版本
1.1 下载安装包
wget https://mirrors.tuna.tsinghua.edu.cn/apache/hive/hive-2.3.6/apache-hive-2.3.6-bin.tar.gz
1.2 解压安装包
tar -zxvf apache-hive-2.3.2-bin.tar.gz -C /home/hap01/apps/
1.3 配置环境变量
通过软连接,当安装包版本变化只需要改变连接即可,不用在去改各种配置。
[hdp01@hdp01 apps]$ ls
apache-hive-2.3.6-bin hadoop-2.7.7
[hdp01@hdp01 apps]$ ln -s apache-hive-2.3.6-bin hive
[hdp01@hdp01 apps]$ ls
apache-hive-2.3.6-bin hadoop-2.7.7 hive
配置环境变量
[hdp01@hdp01 ~]$ vi .bash_profile
export HIVE_HOME=/home/hdp01/apps/hive
export PATH=$PATH:$HIVE_HOME/bin
[hdp01@hdp01 ~]$ source .bash_profile
1.4 初始化元数据
在hive安装目录的bin目录下有个schematool脚本
[hdp01@hdp01 bin]$ ll
总用量 40
-rwxr-xr-x. 1 hdp01 hdp01 881 8月 13 06:04 beeline
drwxrwxr-x. 3 hdp01 hdp01 4096 12月 29 12:02 ext
-rwxr-xr-x. 1 hdp01 hdp01 9838 8月 13 06:06 hive
-rwxr-xr-x. 1 hdp01 hdp01 1900 8月 13 06:04 hive-config.sh
-rwxr-xr-x. 1 hdp01 hdp01 885 8月 13 06:04 hiveserver2
-rwxr-xr-x. 1 hdp01 hdp01 880 8月 13 06:04 hplsql
-rwxr-xr-x. 1 hdp01 hdp01 832 8月 13 06:04 metatool
-rwxr-xr-x. 1 hdp01 hdp01 884 8月 13 06:04 schematool
[hdp01@hdp01 bin]$ pwd
/home/hdp01/apps/hive/bin
初始化元数据:
[hdp01@hdp01 ~]$ schematool -dbType derby -initSchema
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/home/hdp01/apps/apache-hive-2.3.6-bin/lib/log4j-slf4j-impl-2.6.2.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/home/hdp01/apps/hadoop-2.7.7/share/hadoop/common/lib/slf4j-log4j12-1.7.10.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
SLF4J: Actual binding is of type [org.apache.logging.slf4j.Log4jLoggerFactory]
Metastore connection URL: jdbc:derby:;databaseName=metastore_db;create=true
Metastore Connection Driver : org.apache.derby.jdbc.EmbeddedDriver
Metastore connection User: APP
Starting metastore schema initialization to 2.3.0
Initialization script hive-schema-2.3.0.derby.sql
Initialization script completed
schemaTool completed 表示初始化完成,只需要一次
如果失败,修改错误,重新初始化
初始化完成会在当前执行schematool命令目录下生成两个内容:
- derby.log 元数据库的日志文件
- metastore_db:derby数据库的元数据内容
如果hive的元数据库没有实例化,下一步进入hive时会报错:
FAILED: SemanticException org.apache.hadoop.hive.ql.metadata.HiveException: java.lang.RuntimeException: Unable to instantiate org.apache.hadoop.hive.ql.metadata.SessionHiveMetaStoreClient
1.5 启动hive,进入hive客户端
进入hive:
[hdp01@hdp01 ~]$ hive
which: no hbase in (/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/usr/local/jdk1.8.0_211/bin:/usr/local/jdk1.8.0_211/jre/bin:/root/bin:/home/hdp01/.local/bin:/home/hdp01/bin:/home/hdp01/apps/hadoop-2.7.7/bin:/home/hdp01/apps/hadoop-2.7.7/sbin:/home/hdp01/apps/hive/bin)
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/home/hdp01/apps/apache-hive-2.3.6-bin/lib/log4j-slf4j-impl-2.6.2.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/home/hdp01/apps/hadoop-2.7.7/share/hadoop/common/lib/slf4j-log4j12-1.7.10.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
SLF4J: Actual binding is of type [org.apache.logging.slf4j.Log4jLoggerFactory]
Logging initialized using configuration in jar:file:/home/hdp01/apps/apache-hive-2.3.6-bin/lib/hive-common-2.3.6.jar!/hive-log4j2.properties Async: true
Hive-on-MR is deprecated in Hive 2 and may not be available in the future versions. Consider using a different execution engine (i.e. spark, tez) or using Hive 1.X releases.
hive> show databases;
OK
default
Time taken: 3.797 seconds, Fetched: 1 row(s)
创建一个库derby_01
hive> create database derby_01;
OK
Time taken: 0.11 seconds
hive> show databases;
OK
default
derby_01
Time taken: 0.009 seconds, Fetched: 2 row(s)
退出当前客户端,我们切换一个目录再次进入hive:
发现报错了,我们需要在当前目录再次初始化元数据
[hdp01@hdp01 ~]$ ls
apps derby.log hadoopdata jars metastore_db tmpfiles
[hdp01@hdp01 ~]$ cd tmpfiles/
[hdp01@hdp01 tmpfiles]$ hive
which: no hbase in (/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/usr/local/jdk1.8.0_211/bin:/usr/local/jdk1.8.0_211/jre/bin:/root/bin:/home/hdp01/.local/bin:/home/hdp01/bin:/home/hdp01/apps/hadoop-2.7.7/bin:/home/hdp01/apps/hadoop-2.7.7/sbin:/home/hdp01/apps/hive/bin)
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/home/hdp01/apps/apache-hive-2.3.6-bin/lib/log4j-slf4j-impl-2.6.2.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/home/hdp01/apps/hadoop-2.7.7/share/hadoop/common/lib/slf4j-log4j12-1.7.10.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
SLF4J: Actual binding is of type [org.apache.logging.slf4j.Log4jLoggerFactory]
Logging initialized using configuration in jar:file:/home/hdp01/apps/apache-hive-2.3.6-bin/lib/hive-common-2.3.6.jar!/hive-log4j2.properties Async: true
Hive-on-MR is deprecated in Hive 2 and may not be available in the future versions. Consider using a different execution engine (i.e. spark, tez) or using Hive 1.X releases.
hive> show databases;
FAILED: SemanticException org.apache.hadoop.hive.ql.metadata.HiveException: java.lang.RuntimeException: Unabl