在mysql中创建事件

时间:2015-12-03 05:33:09

标签: mysql sql

如何在每周五午夜创建一个事件来备份我的数据库?

  CREATE EVENT baseballbackup
  ON SCHEDULE
  EVERY 1 DAY
  STARTS (TIMESTAMP (CURRENT_DATE) + INTERVAL 1 DAY)
  DO
  DELETE FROM baseball;

我很确定发布的代码是错误的。我不确定什么是正确的语法。

2 个答案:

答案 0 :(得分:0)

语法为:

CREATE EVENT `event_name` 
ON SCHEDULE schedule
[ON COMPLETION [NOT] PRESERVE] 
[ENABLE | DISABLE | DISABLE ON SLAVE]
DO BEGIN
    -- event body
END;

示例:

CREATE 
    EVENT `baseballbackup` 
    ON SCHEDULE EVERY 1 WEEK STARTS '2011-07-24 00:00:00' 
    DO BEGIN
    DELETE FROM baseball WHERE deleted = 1; // or whatever you want
END;

答案 1 :(得分:0)

以下是如何实现你想要的FRIDAY ??

  CREATE EVENT baseballbackup
  ON SCHEDULE
  EVERY 1 WEEK
  STARTS CURRENT_DATE + INTERVAL 4 - WEEKDAY(CURRENT_DATE) DAY + INTERVAL '00:00:00' HOUR_MINUTE_SECOND
  DO BEGIN
    DELETE FROM baseball;
  END;