大数据学习27:Hive元数据清理,从mysql层面删除hive元数据
2017-10-30 22:05
921 查看
由于之前配置了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不会。
2、编写shell(最好用mysql的用户去执行shell):
完成!
由于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 ;
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
完成!
相关文章推荐
- 大数据学习18:Hive在mysql的元数据表的关系和含义
- 从mysql层面删除hive元数据
- Mysql学习笔记——删除重复数据(除id不同)
- 今天差点死了,把innodb数据删除了。学习mysql数据备份与恢复
- MYSQL学习笔记(十六)更新和删除数据
- MySQL 学习<七> 插入、更新与删除数据
- Mysql学习—查看表结构、修改和删除数据表
- mysql学习总结一当数据不存在的时候插入,存在的时候进行更新,删除重复数据
- MySQL学习笔记——删除数据表
- 大数据学习前夕[04]:Mysql安装[Hive]
- Mysql学习3——查看表结构、修改和删除数据表
- MySQL学习笔记——删除数据
- Linux定时清理游戏log及mysql定时任务删除游戏日志数据
- hive修改MySQL里的元数据删除分区
- MySQL学习之插入、删除、更新数据
- 插入,更改,删除数据__mysql学习笔记
- MySQL 5.6学习笔记(查询数据、插入、更新、删除数据)
- 再谈Hive元数据如hive_metadata与Linux里MySQL的深入区别(图文详解)
- MySQL学习笔记之四:插入、更新与删除数据
- Hive学习笔记 --- Hive元数据与数据存储