Hive install
跳到导航
跳到搜索
Hive 3 新特性
- 不再支持 Mr,取而用 Tez 查询引擎,且支持两种查询模式:Container 和 LLAP
- Hive CLI不再支持(被 beeline 取代)
- SQL Standard Authorization 不再支持,且默认建的表就已经是 ACID 表
- 支持 “批查询” (TEZ) 或者 “交互式查询”(LLAP)
Hive 3 其他特性:
- 物化视图重写
- 自动查询缓存
- 会话资源限制:用户会话数,服务器会话数,每个服务器每个用户会话数限制
安装包
wget https://dlcdn.apache.org/hive/hive-3.1.3/apache-hive-3.1.3-bin.tar.gz tar -zxvf apache-hive-3.1.3-bin.tar.gz ln -s apache-hive-3.1.1-bin hive # mkdir /tmp/hive 不用建立。这个目录应该是 hdfs 中的目录,非本地目录
profile
#hive, 20230212, Adam export HIVE_HOME=/opt/hive export PATH=$PATH:$HIVE_HOME/bin source /etc/profile hive --version
INIT
## Init hdfs init-hive-dfs.sh #? hive-config.sh
使用 derby 作为资料库(默认)
## Init Schema cd /opt/hive/bin schematool -dbType derby -initSchema # hive 元数据将清空,但表及数据在 hdfs 中存在(如 test 库 test 表重建后,数据可读。默认:/user/hive/warehouse/test.db/test) # derby 易损坏,如使用虚拟机,休眠后可能会导致库损坏,再次进入 hive 报错。 $ hive SLF4J: Class path contains multiple SLF4J bindings. SLF4J: Found binding in [jar:file:/opt/apache-hive-3.1.3-bin/lib/log4j-slf4j-impl-2.17.1.jar!/org/slf4j/impl/StaticLoggerBinder.class] SLF4J: Found binding in [jar:file:/opt/hadoop-3.3.4/share/hadoop/common/lib/slf4j-reload4j-1.7.36.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] Hive Session ID = e15e49b7-957c-4d21-9073-84fc96a50dad Logging initialized using configuration in jar:file:/opt/apache-hive-3.1.3-bin/lib/hive-common-3.1.3.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: HiveException java.lang.RuntimeException: Unable to instantiate org.apache.hadoop.hive.ql.metadata.SessionHiveMetaStoreClient
使用 MySQL 作为资料库
- ubuntu 直接安装:apt install mysql-server
- 将驱动 /usr/share/java/mysql-connector-j-8.0.31.jar 拷贝到 $HIVE_HOME/lib 目录下(MySQL Connector)
- 创建 $HIVE_HOME/conf/hive-site.xml,可以在 MySQL 中先建好 hive 库,hive 用户(密码:hive)
# hive-site.xml <configuration> <property> <name>javax.jdo.option.ConnectionURL</name> <value>jdbc:mysql://localhost:3306/hive?createDatabaseIfNotExist=true</value> <description>JDBC connect string for a JDBC metastore</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>hive</value> <description>Username to use against metastore database</description> </property> <property> <name>javax.jdo.option.ConnectionPassword</name> <value>hive</value> <description>password to use against metastore database</description> </property> <property> <name>hive.metastore.port</name> <value>9083</value> <description>Hive metastore listener port</description> </property> </configuration>
- Init Schema
schematool -initSchema -dbType mysql