在hive中执行sql语句:SemanticException org.apache.hadoop.hive.ql.metadata.HiveException:

在hive中执行sql语句:SemanticException org.apache.hadoop.hive.ql.metadata.HiveException:

1 hive> show databases;
2 FAILED: SemanticException org.apache.hadoop.hive.ql.metadata.HiveException: java.lang.RuntimeException: Unable to instantiate org.apache.hadoop.hive.ql.metadata.SessionHiveMetaStoreClient

解决方案:

在hive的配置文件hive-site.xml添加如下配置:

 <property>
    <name>datanucleus.schema.autoCreateAll</name>
    <value>true</value>
  </property>

然后删除MySQL中原来的表,重新初始化元数据

drop database hive_metastore;
Query OK, 57 rows affected (0.42 sec)

MariaDB [(none)]> create database hive_metastore;
Query OK, 1 row affected (0.18 sec)

初始化元数据:

[xiaoqiu@s150 /soft/hive/conf]$ schematool -dbType mysql -initSchema

如果没有删除原来映射到MySQL中的表的话会报如下错误:org.apache.hadoop.hive.metastore.HiveMetaException

 1 [xiaoqiu@s150 /soft/hive/conf]$ schematool -dbType mysql -initSchema
 2 SLF4J: Class path contains multiple SLF4J bindings.
 3 SLF4J: Found binding in [jar:file:/soft/apache-hive-2.3.3-bin/lib/log4j-slf4j-impl-2.6.2.jar!/org/slf4j/impl/StaticLoggerBinder.class]
 4 SLF4J: Found binding in [jar:file:/soft/hadoop-2.7.5/share/hadoop/common/lib/slf4j-log4j12-1.7.10.jar!/org/slf4j/impl/StaticLoggerBinder.class]
 5 SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
 6 SLF4J: Actual binding is of type [org.apache.logging.slf4j.Log4jLoggerFactory]
 7 Metastore connection URL:        jdbc:mysql://192.168.109.150:3306/hive_metastore?createDatabaseIfNotExist=true
 8 Metastore Connection Driver :    com.mysql.jdbc.Driver
 9 Metastore connection User:       root
10 Starting metastore schema initialization to 2.3.0
11 Initialization script hive-schema-2.3.0.mysql.sql
12 Error: Duplicate key name 'PCS_STATS_IDX' (state=42000,code=1061)
13 org.apache.hadoop.hive.metastore.HiveMetaException: Schema initialization FAILED! Metastore state would be inconsistent !!
14 Underlying cause: java.io.IOException : Schema script failed, errorcode 2
15 Use --verbose for detailed stacktrace.
16 *** schemaTool failed ***

 

posted @ 2021-07-11 01:56  温家三哥  阅读(973)  评论(0)    收藏  举报