首页 > 解决方案 > 我正在尝试使用所有数据库表的备份来做一个事件

问题描述

我想创建一个事件,每 5 秒在 tables_old 中创建我的表的备份。

我还想知道如何检查表是否未被修改并且不制作该副本。

这是我的代码:

create event ejer5
on schedule every 5 second
do
begin
DECLARE done INT DEFAULT FALSE;
DECLARE table_name varchar(30);
DECLARE cursor1 CURSOR FOR select table_name
from information_schema.tables
where  table_type = 'BASE TABLE'
      and table_schema not in ('information_schema', 'sys',
                               'performance_schema','mysql')
      and table_schema = "world"
order by update_time desc;
DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE;
open cursor1;
bucle:loop
fetch cursor1 into table_name;
IF done THEN
      LEAVE bucle;
    END IF;
SET @c = CONCAT('CREATE TABLE `',table_name,'_old', '` LIKE `',table_name,'`');
PREPARE stmt from @c;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
end loop;
close cursor1;
end // 

标签: mysqldatabasemysql-workbench

解决方案


推荐阅读