mysql - 我正在尝试使用所有数据库表的备份来做一个事件
问题描述
我想创建一个事件,每 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 //
解决方案
推荐阅读
- typescript - 基于另一种类型的子集的类型,其键以特定字符串开头
- php - PHP 7.2 错误消息在哪里?将 PHP 5.6 升级到 7.2,现在错误消息根本没有用
- python - Sci-Kit 学习中的 K-最近邻
- vba - 当任务计划程序中的“用户是否登录”时,VBA 宏无法发送 Outlook 邮件
- powershell - 如何使用 PowerShell Core 别名运行 Bash 命令?
- r - R:返回数据框中最大的两个值的列名
- azure - Http 触发的 Azure 功能 - 即使在空闲时间超过 20 分钟后也不会缩小
- robotframework - RobotFramework 的硬件配置
- python - 在多个 Flask 微服务前使用 Gunicorn
- reactjs - 引导组件不适用于反应应用程序