mysql创建定时任务,每月1号删除上月数据

  • 时间:
  • 出处:跟我学网络
  • 作者:
  • 浏览:764

标签:

1、创建存储过程;

CREATE DEFINER=`gzy`@`%` PROCEDURE `delLastMonth`()
BEGIN
DECLARE lastmonth int;
SET lastmonth = DATE_FORMAT(date_sub(curdate(),interval 1 MONTH),‘%Y%m‘);
DELETE FROM wysytask.user_sign WHERE `month`=lastmonth;
DELETE FROM wysytask.user_resign WHERE `month`=lastmonth;
END

2、创建事件;

CREATE DEFINER=`gzy`@`%` EVENT `delLastMonth` ON SCHEDULE EVERY 1 MONTH STARTS ‘2016-08-01 00:00:05‘ ON COMPLETION NOT PRESERVE ENABLE DO CALL delLastMonth