Hive元数据更新

  Hadoop的core-site.xml中fs.defaultFS配置由于多种原因(集群迁移、集群升级、NameNode主机名更改等)更改,会导致Hive无法通过元数据找到的数据存储地址,因此需要对元数据数据库中的地址更新。

报错场景:

解决方案:

  1. 直接去数据库中修改。我们知道,Hive的元数据信息是存放在关系型数据库中的,我们只要找到存放这些数据的Table,然后用SQL去修改就行了。但是这样比较麻烦,你还得去登录数据库,最重要的是这样还很容易出错,所以不推荐使用。

  2. 使用Hive自带命令修改(推荐)。Hive自带了修改元素相关的命令,我们可以直接使用bin/metatool命令去修改。查看该工具有什么功能。

bin/metatool -help 
Initializing HiveMetaTool.. usage: metatool -dryRun Perform a dry run of updateLocation changes.When run with the dryRun option updateLocation changes are displayed
but not persisted. dryRun is valid only with the updateLocation option. -executeJDOQL <query-string> execute the given JDOQL query -help print this message -listFSRoot
print the current FS root locations -serdePropKey <serde-prop-key> Specify the key for serde property to be updated. serdePropKey option is valid only with updateLocation
option. -tablePropKey <table-prop-key> Specify the key for table property to be updated. tablePropKey option is valid only with updateLocation option.
-updateLocation <new-loc> <old-loc> Update FS root location in the metastore to new location.Both new-loc and old-loc should be valid URIs with valid host names and
schemes.When run with the dryRun option changes are displayed but are not persisted. When run with the serdepropKey/tablePropKey option updateLocation looks for the
serde-prop-key/table-prop-key that is specified and updates its value if found.

 

然后进入Mysql数据库查询:

 

在Hive目录下执行元数据工具更新地址:

# 命令格式如metatool -updateLocation newPath oldPath
./bin/metatool -updateLocation hdfs://hadoop:9000/user/hive/warehouse hdfs://192.168.87.140:9000/user/hive/warehouse

更新完之后,我们可以再看下FS Roots信息是否修改完成:

./bin/metatool -listFSRoot

 已成功修改!

 
 
posted @ 2020-08-20 11:47  buildings  阅读(7307)  评论(0编辑  收藏  举报