hive报错 FAILED: HiveException java.lang.RuntimeException: Unable to instantiate org.apache.hadoop.hive.ql.metadata.SessionHiveMetaStoreClient

现在的情况是执行hive没有出错,但是执行命令出错

$ pwd
/home/hadoop
$ hive
hive> show tables;
FAILED: HiveException java.lang.RuntimeException: Unable to instantiate org.apache.hadoop.hive.ql.metadata.SessionHiveMetaStoreClient
hive> exit;

解决方法:

首先我们去 hive-site.xml 设置Derby数据库的位置:

<property>
    <name>javax.jdo.option.ConnectionURL</name>
    <value>jdbc:derby:/usr/local/hive/metastore_db;databaseName=metastore_db;create=true</value>
</property>

我们删除原来的metadb schema,再重新初始化

$ rm -rf $HIVE_HOME/metastore_db
$ cd $HIVE_HOME
$ schematool -initSchema -dbType derby
...
Initialization script completed
schemaTool completed

现在hive正常工作了:

$ cd
$ hive
hive> show tables;
OK
Time taken: 0.803 seconds

重点:

我发现下次再进hive或者换个终端进hive又会报同样的错,不得不删掉重新初始化,这样之前的数据全没了,这谁顶得住啊!

其实出错的原因:derby数据库限制只能有一个连接

不知道是上一个连接没有关闭、还是没有正常关闭,我们只需删掉/usr/local/hive/metastore_db/dbex.lck文件即可

虽然这样每次执行hsq前都要这样,但总比删除数据好点

如果不行,试试kill掉RunJar进程

ps -ef | grep RunJar

参考链接:

1. https://askubuntu.com/questions/1073035/failed-hiveexception-java-lang-runtimeexception-unable-to-instantiate-org-apac

2. https://stackoverflow.com/questions/35449274/java-lang-runtimeexception-unable-to-instantiate-org-apache-hadoop-hive-ql-meta

3. https://blog.csdn.net/u010886217/article/details/86501199

4. https://bbs.csdn.net/topics/390165816