You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Flink SQL创建Hive Catalog报错:配置的default数据库不存在

问题:Flink创建Hive Catalog提示default数据库不存在

已按官方文档安装依赖,创建Hive Catalog时失败,报错配置的默认数据库default在catalog myhive中不存在,尝试JDBC Catalog也无法正常工作。

执行的SQL语句

CREATE CATALOG myhive WITH (
'type' = 'hive',
'default-database' = 'default',
'hive-conf-dir' = '/opt/hive-conf'
);

报错栈信息

Caused by: org.apache.flink.table.api.ValidationException: Could not execute CREATE CATALOG: (catalogName: [myhive], properties: [{hive-conf-dir=/opt/hive-conf, default-database=default, type=hive}])
at org.apache.flink.table.operations.ddl.CreateCatalogOperation.execute(CreateCatalogOperation.java:75) ~[flink-table-api-java-uber-1.18.0.jar:1.18.0]
at org.apache.flink.table.api.internal.TableEnvironmentImpl.executeInternal(TableEnvironmentImpl.java:1092) ~[flink-table-api-java-uber-1.18.0.jar:1.18.0]
at org.apache.flink.table.gateway.service.operation.OperationExecutor.callOperation(OperationExecutor.java:556) ~[flink-sql-gateway-1.18.0.jar:1.18.0]
at org.apache.flink.table.gateway.service.operation.OperationExecutor.executeOperation(OperationExecutor.java:444) ~[flink-sql-gateway-1.18.0.jar:1.18.0]
at org.apache.flink.table.gateway.service.operation.OperationExecutor.executeStatement(OperationExecutor.java:207) ~[flink-sql-gateway-1.18.0.jar:1.18.0]
at org.apache.flink.table.gateway.service.SqlGatewayServiceImpl.lambda$executeStatement$1(SqlGatewayServiceImpl.java:212) ~[flink-sql-gateway-1.18.0.jar:1.18.0]
at org.apache.flink.table.gateway.service.operation.OperationManager.lambda$submitOperation$1(OperationManager.java:119) ~[flink-sql-gateway-1.18.0.jar:1.18.0]
at org.apache.flink.table.gateway.service.operation.OperationManager$Operation.lambda$run$0(OperationManager.java:258) ~[flink-sql-gateway-1.18.0.jar:1.18.0]
at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) ~[?:?]
at java.util.concurrent.FutureTask.run(Unknown Source) ~[?:?]
at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) ~[?:?]
at java.util.concurrent.FutureTask.run(Unknown Source) ~[?:?]
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) ~[?:?]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) ~[?:?]
... 1 more
Caused by: org.apache.flink.table.catalog.exceptions.CatalogException: Configured default database default doesn't exist in catalog myhive.
    at org.apache.flink.table.catalog.hive.HiveCatalog.open(HiveCatalog.java:309) ~[flink-connector-hive_2.12-1.18.0.jar:1.18.0]
    at org.apache.flink.table.catalog.CatalogManager.createCatalog(CatalogManager.java:309) ~[flink-table-api-java-uber-1.18.0.jar:1.18.0]
    at org.apache.flink.table.operations.ddl.CreateCatalogOperation.execute(CreateCatalogOperation.java:68) ~[flink-table-api-java-uber-1.18.0.jar:1.18.0]
    at org.apache.flink.table.api.internal.TableEnvironmentImpl.executeInternal(TableEnvironmentImpl.java:1092) ~[flink-table-api-java-uber-1.18.0.jar:1.18.0]
    at org.apache.flink.table.gateway.service.operation.OperationExecutor.callOperation(OperationExecutor.java:556) ~[flink-sql-gateway-1.18.0.jar:1.18.0]
    at org.apache.flink.table.gateway.service.operation.OperationExecutor.executeOperation(OperationExecutor.java:444) ~[flink-sql-gateway-1.18.0.jar:1.18.0]
    at org.apache.flink.table.gateway.service.operation.OperationExecutor.executeStatement(OperationExecutor.java:207) ~[flink-sql-gateway-1.18.0.jar:1.18.0]
    at org.apache.flink.table.gateway.service.SqlGatewayServiceImpl.lambda$executeStatement$1(SqlGatewayServiceImpl.java:212) ~[flink-sql-gateway-1.18.0.jar:1.18.0]
    at org.apache.flink.table.gateway.service.operation.OperationManager.lambda$submitOperation$1(OperationManager.java:119) ~[flink-sql-gateway-1.18.0.jar:1.18.0]
    at org.apache.flink.table.gateway.service.operation.OperationManager$Operation.lambda$run$0(OperationManager.java:258) ~[flink-sql-gateway-1.18.0.jar:1.18.0]
    at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) ~[?:?]
    at java.util.concurrent.FutureTask.run(Unknown Source) ~[?:?]
    at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) ~[?:?]
    at java.util.concurrent.FutureTask.run(Unknown Source) ~[?:?]
    at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) ~[?:?]
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) ~[?:?]
    ... 1 more

[ERROR] Could not execute SQL statement. Reason:
org.apache.flink.table.catalog.exceptions.CatalogException: Configured default database default doesn't exist in catalog myhive.

hive-site.xml配置

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<?xml-stylesheet type="text/xsl" href="configuration.xsl"?>
<configuration>
    <property>
        <name>javax.jdo.option.ConnectionURL</name>
        <value>jdbc:postgresql://.....:5432/metastore</value>
    </property>
    <property>
        <name>hive.metastore.uris</name>
        <value>thrift://.....:9083</value>
    </property>

    <property>
        <name>javax.jdo.option.ConnectionDriverName</name>
        <value>org.postgresql.Driver</value>
    </property>

    <property>
        <name>javax.jdo.option.ConnectionUserName</name>
        <value>hive</value>
    </property>

    <property>
        <name>javax.jdo.option.ConnectionPassword</name>
        <value>hive</value>
    </property>

    <property>
        <name>org.jpox.autoCreateSchema</name>
        <value>true</value>
    </property>

</configuration>

Hive命令行验证结果

Logging initialized using configuration in file:/opt/hive/conf/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
abc
default
Time taken: 1.374 seconds, Fetched: 2 row(s)
hive>

解决方案

  • 检查Hive metastore连通性:
    用nc -zv <metastore-host> 9083测试Flink节点到Hive metastore服务的端口连通性,排查防火墙、metastore服务状态。
  • 确认配置目录权限与完整性:
    检查Flink进程是否有权限读取/opt/hive-conf目录,确保hive-site.xml无格式错误、内容完整。
  • 指定Hive版本参数:
    创建Catalog时添加hive-version参数匹配实际Hive版本,示例:
    CREATE CATALOG myhive WITH (
    'type' = 'hive',
    'default-database' = 'default',
    'hive-conf-dir' = '/opt/hive-conf',
    'hive-version' = '2.3.9' -- 替换为你的Hive版本
    );
    
  • 验证依赖兼容性:
    确认flink-connector-hive包版本与Hive版本匹配,将Hive JDBC驱动(如postgresql驱动)放入Flink的lib目录。
  • 临时跳过默认库检查:
    不指定default-database参数,创建后手动切换数据库:
    CREATE CATALOG myhive WITH (
    'type' = 'hive',
    'hive-conf-dir' = '/opt/hive-conf'
    );
    USE CATALOG myhive;
    USE default;
    

内容的提问来源于stack exchange,提问作者taymedee

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.06 08:45:55