gpt4 book ai didi

mysql 事件无法调用过程来分区数据库

转载 作者:行者123 更新时间:2023-11-29 17:38:31 25 4
gpt4 key购买 nike

有人遇到和我一样的问题吗?请帮忙!!

我有两个过程和一个事件,当我从命令行单独调用它们时,这些过程工作得很好。

但是这些程序不能从mysql事件内部调用。下面是我的程序、mysql事件以及我如何检查有效结果:

USE ims_db;
DELIMITER;
DROP PROCEDURE IF EXISTS CreatePartition$$
CREATE PROCEDURE CreatePartition(day_keep_data INT)
BEGIN
DECLARE partition_temp TEXT;
DECLARE partition_name CHAR(12);
DECLARE partition_threshold INT DEFAULT 0;
DECLARE day_temp INT;
SET day_temp = day_keep_data;

SET @sql = concat('ALTER TABLE ims_db.ims_counter PARTITION BY RANGE(trigger_time)(');
loop_change_partition: LOOP
IF day_temp <= 0 THEN
LEAVE loop_change_partition;
END IF;

SET day_temp = day_temp - 1;
SET partition_threshold = UNIX_TIMESTAMP() - 86400*day_temp;
SET partition_name = concat('p', CURRENT_DATE() - INTERVAL day_temp DAY + 0);
SET partition_temp = concat('PARTITION', partition_name, ' VALUES LESS THAN (', partition_threshold,'), ');
SET @sql = concat(@sql, partition_temp);
END LOOP loop_change_partition;

SET partition_name = concat('p', CURRENT_DATE() + INTERVAL 1 DAY + 0);
SET partition_temp = concat('PARTITION', partition_name, ' VALUES LESS THAN MAXVALUE);');
SET @sql = concat(@sql, partition_temp);
prepare stmt from @sql;
execute stmt;
deallocate prepare stmt;
END$$
DELIMITER ;


DELIMITER $$
DROP PROCEDURE IF EXISTS DeleteOldData$$
CREATE PROCEDURE DeleteOldData(day_keep_data INT)
BEGIN
SET @sql = concat('DELETE FROM ims_db.ims_counter WHERE ims_db.ims_counter.id > 0
AND ims_db.ims_counter.trigger_time < ', UNIX_TIMESTAMP() - 86400*day_keep_data);
prepare stmt from @sql;
execute stmt;
deallocate prepare stmt;
ALTER TABLE ims_counter REMOVE PARTITIONING;
END$$
DELIMITER ;

-- DELIMITER $$
-- CREATE FUNCTION ims_daily_work() RETURNS INT(11)
-- BEGIN
-- CALL DeleteOldData(30);
-- CALL CreatePartition(30);
-- END $$
-- DELIMITER ;

DELIMITER $$
CREATE EVENT IMSDailyWork
ON SCHEDULE EVERY 30 SECOND STARTS CURRENT_TIMESTAMP + INTERVAL 10 SECOND
DO
BEGIN
CALL DeleteOldData(30);
CALL CreatePartition(30);
-- SELECT ims_daily_work();
END$$
DELIMITER ;

如何检查有效结果:

  • 运行命令:显示表状态,如“ims_counter”\G -> 检查 Create_options: -> 它为空
  • 运行上述所有事件和过程后 -> 再次检查 Create_options: -> 它应该是“分区”,但我的问题是没有这样的“分区”。

最佳答案

我找到了解决方案:这是因为我的“event_scheduler”关闭了,所以无法启动任何EVENT。

  1. to check event status: show global variables like 'event_scheduler';
  2. to enable event_scheduler: set global event_scheduler=1;

关于mysql 事件无法调用过程来分区数据库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50127380/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com