OceanBase社区版,版本号4.3.5-lts
在存储过程中,好像查询不到任何information_schema.partitions数据。有什么办法能解决?业务避免不了这个表数据的查询
本地复现出来了。使用partitions表是想统计什么呢这边看下ob库是否有替代表
partition_name、partition_description、table_schema、table_name
主要是用来指定一些表名去查询分区数据,用来drop partition清理一些分区数据。
学习
drop procedure if exists yazx_bizsec.truncate_partition_list_columns;;;;;
create procedure if not exists yazx_bizsec.truncate_partition_list_columns(IN t_schema varchar(255) ,IN t_name varchar(255),IN p_name varchar(255))
begin
declare is_exists int;
declare p_name_normal varchar(255);
declare p_name_old varchar(255);
select concat('`',replace(p_name,'`',''),'_',MD5(p_name),'`') into p_name_normal;
select
partition_name,
1 as tmp into p_name_old, is_exists
from information_schema.partitions
where table_schema = t_schema and table_name = t_name and partition_description = concat("'",p_name,"'");
if is_exists = 1 and p_name_old !='p_node_yazx_bizsec' then
set @sql_drop_p = concat('alter table ',t_schema,'.',t_name,' drop partition `',p_name_old,'`');
prepare stmt from @sql_drop_p;
execute stmt;
deallocate prepare stmt;
set @sql_add_p = concat('alter table ',t_schema,'.',t_name,' add partition (partition ',p_name_normal,' values in (',concat("'",p_name,"'"),'))');
prepare stmt from @sql_add_p;
execute stmt;
deallocate prepare stmt;
end if;
if is_exists is null then
set @sql_add_p = concat('alter table ',t_schema,'.',t_name,' add partition (partition ',p_name_normal,' values in (',concat("'",p_name,"'"),'))');
prepare stmt from @sql_add_p;
execute stmt;
deallocate prepare stmt;
end if;
end;;;;;
比如这是其中一个存储过程的片段
你这里没有执行存储过程只是创建了
call yazx_bizsec.truncate_partition_list_columns(‘yazx_bizsec’,‘表名xxx’,‘业务节点名称’);
有些定时任务会定时执行
然后每次都没走到预期的清理和重建,排查是视图内部查不到那个partitions表的数据。
执行任务的用户是root么
是新建的用户,不是root
用root测一下
root可以,暂时只能用root账号吗?

新建的用户权限够么,查不到大概率是权限问题
还要怎么给才能有权限在存储过程里面查到?
加一下information schema库的表权限,用新用户查询看看是否正常呢?
mysql> GRANT ALL PRIVILEGES ON information_schema.* TO ‘yazx’@’%’;
ERROR 1044 (42000): Access denied for user ‘root’@’%’ to database ‘information_schema’
[172.18.0.7:2882] [2026-04-20 08:54:15.075026] [YB42AC120007-00064FBAB48C9899-0-0]
mysql>
似乎不行
打卡
