hive执行sql语句报错“Unable to instantiate org.apache.hadoop.hive.ql.metadata.SessionHiveMetaStoreClient

hive执行sql语句报错“Unable to instantiate org.apache.hadoop.hive.ql.metadata.SessionHiveMetaStoreClient

在安装了hive的节点上用如下命令启动 metastore 服务:

# 后台启动 metastore 服务器端,默认使用 9083 端口
nohup hive --service metastore &

# 或者使用指定的端口号:
nohup hive --service metastore -p 9083 &

但是,启动失败了,

原因是由于我之前安装的是hive1.2.0并且启动过,那么在mysql中已经生成了metastore数据库,就会提示下图中的错误。需要执行命令schematool -dbType mysql –initSchema初始化话hive。hive执行sql语句报错“Unable to instantiate org.apache.hadoop.hive.ql.metadata.SessionHiveMetaStoreClient_第1张图片

 但是在初始化的时候,又报错如下:

[root@node3 hive-2.3.4]# schematool -dbType mysql -initSchema
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/opt/hive-2.3.4/lib/log4j-slf4j-impl-2.6.2.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/opt/hadoop-2.6.5/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:mysql://node1:3306/hive?createDatabaseIfNotExist=true
Metastore Connection Driver :	 com.mysql.jdbc.Driver
Metastore connection User:	 root
Starting metastore schema initialization to 2.3.0
Initialization script hive-schema-2.3.0.mysql.sql
Error: Duplicate key name 'PCS_STATS_IDX' (state=42000,code=1061)
org.apache.hadoop.hive.metastore.HiveMetaException: Schema initialization FAILED! Metastore state would be inconsistent !!
Underlying cause: java.io.IOException : Schema script failed, errorcode 2
Use --verbose for detailed stacktrace.
*** schemaTool failed ***

Schema initialization FAILED! Metastore state would be inconsistent !!
架构初始化失败! Metastore状态不一致!!

解决方法如下:

  1. 删除metastore_db文件,我的这个文件是在home目录下,用 rm -r 删除

  2. 删除mysql数据库中对应的database。drop database metastore_db; 


        javax.jdo.option.ConnectionURL
        jdbc:mysql://node1:3306/metastore?createDatabaseIfNotExist=true

在配置文件中如果配置的数据库名字是:metastore,则将该数据库删除即可。

进行以上操作后,进行重新初始化:schematool -dbType mysql -initSchema

然后进入hive,查询测试一下,成果解决。

hive执行sql语句报错“Unable to instantiate org.apache.hadoop.hive.ql.metadata.SessionHiveMetaStoreClient_第2张图片

 

你可能感兴趣的:(hive,hive,sql,apache)