通过删除mysql元数据来删除hive表信息
文章目录
先创建表
create table dept_partition(
deptno int,
dname string,
loc string
)
partitioned by (month string)
row format delimited fields terminated by '\t';
加载数据
load data local inpath '/home/hadoop/data/asd.txt' into table dept_partition partition(month='201901');
load data local inpath '/home/hadoop/data/asd.txt' into table dept_partition partition(month='201902');
load data local inpath '/home/hadoop/data/asd.txt' into table dept_partition partition(month='201903');
可以在网页端看到hive目录里已经有了表和分区
删除一个分区
1.partition_key_vals
该表存储分区字段值
2.partition_params
该表存储分区的属性信息
3.partitions
回hive查看果真分区被删了
删除整个表
从元数据删除Hive的表需要得到五个ID.
TBL_ID:表ID
SD_ID :序列化配置信息
CD_ID:字段信息ID
PART_ID:分区ID
SERDE_ID:序列化类ID
TBL_ID(56)和SD_ID(61,62,63,64)可以从TBLS表(存表的创建信息)得到,CD_ID(56),SERDE_ID(64)可以从SDS表(表的压缩和格式文件存储的基本信息)得到,PART_ID(11,12,13)可以从PARTITIONS表(存储表分区的基本信息)中得到。
1.partition_key_vals
2.partition_params
3.partitions
4.partition_keys
该表存储分区的字段信息
5.TABLE_PARAMS
该表存储表/视图的属性信息
mysql> delete from table_params where tbl_id='56';
6.tbls
存表的创建信息
mysql> delete from tbls where tbl_id='56';
此时hive已经删除了这个表
但是元数据还没清除干净,下面的步骤可不做
7.SERDE_PARAMS
该表存储序列化的一些属性、格式信息,比如:行、列分隔符
mysql> delete from SERDE_PARAMS where serde_id='64';
8.SDS
表的压缩和格式文件存储的基本信息(包括分区的具体分区,因此删3个)
mysql> delete from Sds where sd_id='61' or sd_id='62' or sd_id='63' or sd_id='64';
9.COLUMNS_V2
该表存储表对应的字段信息
mysql> delete from COLUMNS_V2 where cd_id='56';
10.serdes
该表存储序列化使用的类信息
mysql> delete from serdes where serde_id='64';