根据元数据存储的介质不同,分为下面两个版本,其中 derby 属于内嵌模式,无需配置直接可用。实际生产环境中则使用 mysql 来进行元数据的存储。
(1) 内置 derby 版:
解压 hive 安装包 , bin/hive 启动即可使用 .
缺点:不同路径启动 hive,每一个 hive 拥有一套自己的元数据,无法共享
理解 : 在哪个目录下启动,就会在那个目录下生成 derby.log 和 metastore.db,只有在此目录下再次启动才可以继续使用上次的元数据库.
schematool -dbType derby -initSchema
(2) mysql 版:
解压安装hive(版本)
修改hive配置文件# 修改Hadoop_HOMEvi conf/hive-env.sh
# 配置元数据库信息vi conf/hive-site.xml1234
配置 Mysql 元数据库信息javax.jdo.option.ConnectionURL
jdbc:mysql://localhost:3306/hive?createDatabaseIfNotExist=true
JDBC connect string for a JDBC metastore
javax.jdo.option.ConnectionDriverName
com.mysql.jdbc.Driver
Driver class name for a JDBC metastore
javax.jdo.option.ConnectionUserName
root
username to use against metastore database
javax.jdo.option.ConnectionPassword
123456
password to use against metastore database123456789101112131415161718192021222324252627
将mysql的连接jar包拷贝到$HIVE_HOME/lib目录下
配置元数据类型为mysql
schematool -dbType mysql -initSchema[root@iZm5edx24ecfoc8828jj1pZ bin]# service mysqld startStarting mysqld: [ OK ][root@iZm5edx24ecfoc8828jj1pZ bin]# schematool -dbType mysql -initSchemaSLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/opt/module/apache-hive-2.3.4-bin/lib/log4j-slf4j-impl-2.6.2.jar!/org/slf4j/impl/StaticLoggerBinder.class]SLF4J: Found binding in [jar:file:/opt/module/hadoop-2.7.4/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:mysql://localhost:3306/hive?createDatabaseIfNotExist=true
Metastore Connection Driver : com.mysql.jdbc.Driver
Metastore connection User: root
Loading class `com.mysql.jdbc.Driver'. This is deprecated. The new driver class is `com.mysql.cj.jdbc.Driver'. The driver is automatically registered via the SPI and manual loading of the driver class is generally unnecessary.
Starting metastore schema initialization to 2.3.0
Initialization script hive-schema-2.3.0.mysql.sql
Initialization script completed
schemaTool completed12345678910111213141516
启动 bin/hive 后mysql会生成hive数据库及相关表