Hive metastore database is not initialized. Please use schematool(...) to create the schema.

本文解决Hive启动时报元数据库未初始化的问题,通过使用schematool工具初始化数据库并处理重复函数错误。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

同样遇见问题,这篇文章解决了 http://blog.youkuaiyun.com/xiaoshunzi111/article/details/51906049

一:问题:Exception in thread “main” java.lang.RuntimeException: Hive metastore database is not initialized. Please use schematool (e.g. ./schematool -initSchema -dbType …) to create the schema.

异常操作如下:

[root@master lib]# Hive
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/usr/home/apache-hive-2.1.0-bin/lib/log4j-slf4j-impl-2.4.1.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/usr/home/Hadoop-2.5.2/share/hadoop/common/lib/slf4j-log4j12-1.7.5.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:/usr/home/apache-hive-2.1.0-bin/lib/hive-common-2.1.0.jar!/hive-log4j2.properties Async: true
Exception in thread "main" Java.lang.RuntimeException: org.apache.hadoop.hive.ql.metadata.HiveException: org.apache.hadoop.hive.ql.metadata.HiveException: MetaException(message:Hive metastore database is not initializedPlease use schematool (e.g. ./schematool -initSchema -dbType ...) to create the schema. If needed, don't forget to include the option to auto-create the underlying database in your JDBC connection string (e.g. ?createDatabaseIfNotExist=true for MySQL))
        at org.apache.hadoop.hive.ql.session.SessionState.start(SessionState.java:578)
        at org.apache.hadoop.hive.ql.session.SessionState.beginStart(SessionState.java:518)
        at org.apache.hadoop.hive.cli.CliDriver.run(CliDriver.java:705)
        at org.apache.hadoop.hive.cli.CliDriver.main(CliDriver.java:641)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:601)
        at org.apache.hadoop.util.RunJar.main(RunJar.java:212)
Caused by: org.apache.hadoop.hive.ql.metadata.HiveException: org.apache.hadoop.hive.ql.metadata.HiveException: MetaException(message:Hive metastore database is not initialized. Please use schematool (e.g. ./schematool -initSchema -dbType ...) to create the schema. If needed, don't forget to include the option to auto-create the underlying database in your JDBC connection string (e.g. ?createDatabaseIfNotExist=true for mysql))
        at org.apache.hadoop.hive.ql.metadata.Hive.registerAllFunctionsOnce(Hive.java:226)
        at org.apache.hadoop.hive.ql.metadata.Hive.<init>(Hive.java:366)
        at org.apache.hadoop.hive.ql.metadata.Hive.create(Hive.java:310)
        at org.apache.hadoop.hive.ql.metadata.Hive.getInternal(Hive.java:290)
        at org.apache.hadoop.hive.ql.metadata.Hive.get(Hive.java:266)
        at org.apache.hadoop.hive.ql.session.SessionState.start(SessionState.java:545)
        ... 8 more
Caused by: org.apache.hadoop.hive.ql.metadata.HiveException: MetaException(message:Hive metastore database is not initialized. Please use schematool (e.g. ./schematool -initSchema -dbType ...) to create the schema. If needed, don't forget to include the option to auto-create the underlying database in your JDBC connection string (e.g. ?createDatabaseIfNotExist=true for mysql))
        at org.apache.hadoop.hive.ql.metadata.Hive.getAllFunctions(Hive.java:3593)
        at org.apache.hadoop.hive.ql.metadata.Hive.reloadFunctions(Hive.java:236)
        at org.apache.hadoop.hive.ql.metadata.Hive.registerAllFunctionsOnce(Hive.java:221)
        ... 13 more
Caused by: MetaException(message:Hive metastore database is not initialized. Please use schematool (e.g. ./schematool -initSchema -dbType ...) to create the schema. If needed, don't forget to include the option to auto-create the underlying database in your JDBC connection string (e.g. ?createDatabaseIfNotExist=true for mysql))
        at org.apache.hadoop.hive.ql.metadata.Hive.getMSC(Hive.java:3364)
        at org.apache.hadoop.hive.ql.metadata.Hive.getMSC(Hive.java:3336)
        at org.apache.hadoop.hive.ql.metadata.Hive.getAllFunctions(Hive.java:3590)
        ... 15 more



二:原因:由于没有初始化元数据库; 


三:解决方法: 
命令行输入:./schematool -initSchema -dbType derby 
输入完这句之后可能会报如下错: 
Error: FUNCTION ‘NUCLEUS_ASCII’ already exists. (state=X0Y68,code=30000) 
原因:这可能是因为你的metastore_db文件夹已经存在; 
解决办法:将当前文件夹下的metastor_db文件夹删除,重新输入指令:./schematool -initSchema -dbType derby即可;

操作如下:

[root@master bin]# ./schematool -initSchema -dbType derby
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/usr/home/apache-hive-2.1.0-bin/lib/log4j-slf4j-impl-2.4.1.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/usr/home/hadoop-2.5.2/share/hadoop/common/lib/slf4j-log4j12-1.7.5.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.1.0
Initialization script hive-schema-2.1.0.derby.sql
Initialization script completed
schemaTool completed


hive> create database bclcredits; 2025-06-18 16:01:34,708 INFO conf.HiveConf: Using the default value passed in for log id: 949847db-5ab3-4891-b83b-d3071c4b727b 2025-06-18 16:01:34,709 INFO session.SessionState: Updating thread name to 949847db-5ab3-4891-b83b-d3071c4b727b main 2025-06-18 16:01:34,710 INFO ql.Driver: Compiling command(queryId=aaa_20250618160134_462642e2-55ea-4fa2-bd3d-7f4f5dbee217): create database bclcredits 2025-06-18 16:01:34,717 INFO ql.Driver: Concurrency mode is disabled, not creating a lock manager 2025-06-18 16:01:34,722 INFO ql.Driver: Semantic Analysis Completed (retrial = false) 2025-06-18 16:01:34,722 INFO ql.Driver: Returning Hive schema: Schema(fieldSchemas:null, properties:null) 2025-06-18 16:01:34,722 INFO ql.Driver: Completed compiling command(queryId=aaa_20250618160134_462642e2-55ea-4fa2-bd3d-7f4f5dbee217); Time taken: 0.012 seconds 2025-06-18 16:01:34,722 INFO reexec.ReExecDriver: Execution #1 of query 2025-06-18 16:01:34,723 INFO ql.Driver: Concurrency mode is disabled, not creating a lock manager 2025-06-18 16:01:34,723 INFO ql.Driver: Executing command(queryId=aaa_20250618160134_462642e2-55ea-4fa2-bd3d-7f4f5dbee217): create database bclcredits 2025-06-18 16:01:34,723 INFO ql.Driver: Starting task [Stage-0:DDL] in serial mode 2025-06-18 16:01:34,742 INFO sqlstd.SQLStdHiveAccessController: Created SQLStdHiveAccessController for session context : HiveAuthzSessionContext [sessionString=949847db-5ab3-4891-b83b-d3071c4b727b, clientType=HIVECLI] 2025-06-18 16:01:34,744 WARN session.SessionState: METASTORE_FILTER_HOOK will be ignored, since hive.security.authorization.manager is set to instance of HiveAuthorizerFactory. 2025-06-18 16:01:34,745 INFO metastore.HiveMetaStoreClient: Mestastore configuration metastore.filter.hook changed from org.apache.hadoop.hive.metastore.DefaultMetaStoreFilterHookImpl to org.apache.hadoop.hive.ql.security.authorization.plugin.AuthorizationMetaStoreFilterHook 2025-06-18 16:01:34,746 INFO metastore.HiveMetaStore: 0: Cleaning up thread local RawStore... 2025-06-18 16:01:34,746 INFO HiveMetaStore.audit: ugi=aaa ip=unknown-ip-addr cmd=Cleaning up thread local RawStore... 2025-06-18 16:01:34,746 INFO metastore.HiveMetaStore: 0: Done cleaning up thread local RawStore 2025-06-18 16:01:34,747 INFO HiveMetaStore.audit: ugi=aaa ip=unknown-ip-addr cmd=Done cleaning up thread local RawStore 2025-06-18 16:01:34,748 INFO metastore.HiveMetaStore: 0: Opening raw store with implementation class:org.apache.hadoop.hive.metastore.ObjectStore 2025-06-18 16:01:34,748 WARN metastore.ObjectStore: datanucleus.autoStartMechanismMode is set to unsupported value null . Setting it to value: ignored 2025-06-18 16:01:34,748 INFO metastore.ObjectStore: ObjectStore, initialize called 2025-06-18 16:01:34,751 INFO metastore.MetaStoreDirectSql: Using direct SQL, underlying DB is MYSQL 2025-06-18 16:01:34,752 INFO metastore.ObjectStore: Initialized ObjectStore 2025-06-18 16:01:34,753 INFO metastore.RetryingMetaStoreClient: RetryingMetaStoreClient proxy=class org.apache.hadoop.hive.ql.metadata.SessionHiveMetaStoreClient ugi=aaa (auth:SIMPLE) retries=1 delay=1 lifetime=0 2025-06-18 16:01:34,755 WARN metastore.ObjectStore: datanucleus.autoStartMechanismMode is set to unsupported value null . Setting it to value: ignored 2025-06-18 16:01:34,756 INFO metastore.ObjectStore: ObjectStore, initialize called 2025-06-18 16:01:34,758 INFO metastore.MetaStoreDirectSql: Using direct SQL, underlying DB is MYSQL 2025-06-18 16:01:34,758 INFO metastore.ObjectStore: Initialized ObjectStore 2025-06-18 16:01:34,759 INFO metastore.RetryingMetaStoreClient: RetryingMetaStoreClient proxy=class org.apache.hadoop.hive.ql.metadata.SessionHiveMetaStoreClient ugi=aaa (auth:SIMPLE) retries=1 delay=1 lifetime=0 2025-06-18 16:01:34,759 INFO metastore.HiveMetaStore: 0: create_database: Database(name:bclcredits, description:null, locationUri:hdfs://localhost:9000/user/hive/warehouse/bclcredits.db, parameters:null, ownerName:aaa, ownerType:USER, catalogName:hive) 2025-06-18 16:01:34,759 INFO HiveMetaStore.audit: ugi=aaa ip=unknown-ip-addr cmd=create_database: Database(name:bclcredits, description:null, locationUri:hdfs://localhost:9000/user/hive/warehouse/bclcredits.db, parameters:null, ownerName:aaa, ownerType:USER, catalogName:hive) 2025-06-18 16:01:34,764 ERROR metastore.RetryingHMSHandler: AlreadyExistsException(message:Database bclcredits already exists) at org.apache.hadoop.hive.metastore.HiveMetaStore$HMSHandler.create_database(HiveMetaStore.java:1311) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.apache.hadoop.hive.metastore.RetryingHMSHandler.invokeInternal(RetryingHMSHandler.java:147) at org.apache.hadoop.hive.metastore.RetryingHMSHandler.invoke(RetryingHMSHandler.java:108) at com.sun.proxy.$Proxy38.create_database(Unknown Source) at org.apache.hadoop.hive.metastore.HiveMetaStoreClient.createDatabase(HiveMetaStoreClient.java:809) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.apache.hadoop.hive.metastore.RetryingMetaStoreClient.invoke(RetryingMetaStoreClient.java:212) at com.sun.proxy.$Proxy39.createDatabase(Unknown Source) at org.apache.hadoop.hive.ql.metadata.Hive.createDatabase(Hive.java:477) at org.apache.hadoop.hive.ql.exec.DDLTask.createDatabase(DDLTask.java:4828) at org.apache.hadoop.hive.ql.exec.DDLTask.execute(DDLTask.java:393) at org.apache.hadoop.hive.ql.exec.Task.executeTask(Task.java:205) at org.apache.hadoop.hive.ql.exec.TaskRunner.runSequential(TaskRunner.java:97) at org.apache.hadoop.hive.ql.Driver.launchTask(Driver.java:2664) at org.apache.hadoop.hive.ql.Driver.execute(Driver.java:2335) at org.apache.hadoop.hive.ql.Driver.runInternal(Driver.java:2011) at org.apache.hadoop.hive.ql.Driver.run(Driver.java:1709) at org.apache.hadoop.hive.ql.Driver.run(Driver.java:1703) at org.apache.hadoop.hive.ql.reexec.ReExecDriver.run(ReExecDriver.java:157) at org.apache.hadoop.hive.ql.reexec.ReExecDriver.run(ReExecDriver.java:218) at org.apache.hadoop.hive.cli.CliDriver.processLocalCmd(CliDriver.java:239) at org.apache.hadoop.hive.cli.CliDriver.processCmd(CliDriver.java:188) at org.apache.hadoop.hive.cli.CliDriver.processLine(CliDriver.java:402) at org.apache.hadoop.hive.cli.CliDriver.executeDriver(CliDriver.java:821) at org.apache.hadoop.hive.cli.CliDriver.run(CliDriver.java:759) at org.apache.hadoop.hive.cli.CliDriver.main(CliDriver.java:683) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.apache.hadoop.util.RunJar.run(RunJar.java:323) at org.apache.hadoop.util.RunJar.main(RunJar.java:236) 2025-06-18 16:01:34,764 ERROR exec.DDLTask: Failed org.apache.hadoop.hive.ql.metadata.HiveException: Database bclcredits already exists at org.apache.hadoop.hive.ql.exec.DDLTask.createDatabase(DDLTask.java:4832) at org.apache.hadoop.hive.ql.exec.DDLTask.execute(DDLTask.java:393) at org.apache.hadoop.hive.ql.exec.Task.executeTask(Task.java:205) at org.apache.hadoop.hive.ql.exec.TaskRunner.runSequential(TaskRunner.java:97) at org.apache.hadoop.hive.ql.Driver.launchTask(Driver.java:2664) at org.apache.hadoop.hive.ql.Driver.execute(Driver.java:2335) at org.apache.hadoop.hive.ql.Driver.runInternal(Driver.java:2011) at org.apache.hadoop.hive.ql.Driver.run(Driver.java:1709) at org.apache.hadoop.hive.ql.Driver.run(Driver.java:1703) at org.apache.hadoop.hive.ql.reexec.ReExecDriver.run(ReExecDriver.java:157) at org.apache.hadoop.hive.ql.reexec.ReExecDriver.run(ReExecDriver.java:218) at org.apache.hadoop.hive.cli.CliDriver.processLocalCmd(CliDriver.java:239) at org.apache.hadoop.hive.cli.CliDriver.processCmd(CliDriver.java:188) at org.apache.hadoop.hive.cli.CliDriver.processLine(CliDriver.java:402) at org.apache.hadoop.hive.cli.CliDriver.executeDriver(CliDriver.java:821) at org.apache.hadoop.hive.cli.CliDriver.run(CliDriver.java:759) at org.apache.hadoop.hive.cli.CliDriver.main(CliDriver.java:683) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.apache.hadoop.util.RunJar.run(RunJar.java:323) at org.apache.hadoop.util.RunJar.main(RunJar.java:236) Caused by: AlreadyExistsException(message:Database bclcredits already exists) at org.apache.hadoop.hive.metastore.HiveMetaStore$HMSHandler.create_database(HiveMetaStore.java:1311) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.apache.hadoop.hive.metastore.RetryingHMSHandler.invokeInternal(RetryingHMSHandler.java:147) at org.apache.hadoop.hive.metastore.RetryingHMSHandler.invoke(RetryingHMSHandler.java:108) at com.sun.proxy.$Proxy38.create_database(Unknown Source) at org.apache.hadoop.hive.metastore.HiveMetaStoreClient.createDatabase(HiveMetaStoreClient.java:809) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.apache.hadoop.hive.metastore.RetryingMetaStoreClient.invoke(RetryingMetaStoreClient.java:212) at com.sun.proxy.$Proxy39.createDatabase(Unknown Source) at org.apache.hadoop.hive.ql.metadata.Hive.createDatabase(Hive.java:477) at org.apache.hadoop.hive.ql.exec.DDLTask.createDatabase(DDLTask.java:4828) ... 22 more 2025-06-18 16:01:34,768 INFO reexec.ReOptimizePlugin: ReOptimization: retryPossible: false FAILED: Execution Error, return code 1 from org.apache.hadoop.hive.ql.exec.DDLTask. Database bclcredits already exists 2025-06-18 16:01:34,769 ERROR ql.Driver: FAILED: Execution Error, return code 1 from org.apache.hadoop.hive.ql.exec.DDLTask. Database bclcredits already exists 2025-06-18 16:01:34,769 INFO ql.Driver: Completed executing command(queryId=aaa_20250618160134_462642e2-55ea-4fa2-bd3d-7f4f5dbee217); Time taken: 0.046 seconds 2025-06-18 16:01:34,769 INFO ql.Driver: Concurrency mode is disabled, not creating a lock manager 2025-06-18 16:01:34,772 INFO conf.HiveConf: Using the default value passed in for log id: 949847db-5ab3-4891-b83b-d3071c4b727b 2025-06-18 16:01:34,772 INFO session.SessionState: Resetting thread name to main
最新发布
06-20
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值