大数据学习27:Hive元数据清理,从mysql层面删除hive元数据

转自:https://blog.csdn.net/ggwxk1990/article/details/78397973

由于之前配置了hive,hdfs 被格式化了,导致现在hive上原来的元数据没有清理掉。 

由于hive 上所有元数据均保存在mysql中,所以,可以从mysql上删除表相关信息即可删除hive表,而且不会影响hdfs上数据。 
分析: 
hive在mysql上的相关元数据表关系图: 
这里写图片描述
Hive在mysql的元数据表的关系和含义这篇博文中有详细字段说明: 
http://blog.csdn.net/ggwxk1990/article/details/78162442

解决方法: 
1、先在 mysql 中建存储过程 
说明: 
建的存储过程名字为t1,输入为tbl_id。因为表名可能重复,但是tbl_id不会。

DELIMITER // 
drop procedure if exists t1;
create  procedure t1 ( in tbinput int) 
begin
    declare v_sd_id int ;
    declare v_part_id int ;
    declare v_cd_id int ;
    declare v_serde_id int ;

    select tbinput;
    select SD_ID into v_sd_id from tbls where TBL_ID = tbinput;
    select part_id  into v_part_id from partitions where tbl_id = tbinput;
    select cd_id , serde_id into v_cd_id,v_serde_id from sds where sd_id = v_sd_id;
    select v_sd_id,v_part_id,v_cd_id,v_serde_id;

    if v_part_id is not  null then 
        delete from partition_params where part_id = v_part_id;
        delete from partition_key_vals where part_id = v_part_id;

    end if;
    delete from serdes where serde_id = v_serde_id;
    delete from serde_params where serde_id = v_serde_id;
    delete from columns_v2 where cd_id = v_cd_id;
    delete from sds where sd_id = v_sd_id;
    delete from partitions where tbl_id = tbinput;
    delete from partition_keys where tbl_id = tbinput;
    delete from table_params where tbl_id = tbinput;
    delete from tbls where tbl_id = tbinput;

end ;
//
delimiter ; 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32

2、编写shell(最好用mysql的用户去执行shell):

hadoop002:mysqladmin:/usr/local/mysql:>cat mysql_delete.sh 
#!/bin/bash
source /usr/local/mysql/.bash_profile
mysql -uroot -ppassword hive3 -e "
SET FOREIGN_KEY_CHECKS = 0; 
call t1(71);  
SET FOREIGN_KEY_CHECKS = 1;
quit" >> /tmp/mysql_delete.log
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8

完成!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值