mysql event

时间:2023-03-09 13:39:14
mysql event

1.定时调用 存储过程

DELIMITER $$

ALTER DEFINER=`root`@`localhost` EVENT `event_stroke_ArchivesReportDataRefreshDaily` ON SCHEDULE EVERY 1 DAY STARTS '2012-01-01 00:10:00' ON COMPLETION NOT PRESERVE ENABLE DO CALL proc_stroke_ArchivesReportDataRefresh()$$

DELIMITER ;

2.定时执行sql语句

DELIMITER $$

ALTER DEFINER=`root`@`localhost` EVENT `event_stroke_ArchivesReportDataRefreshDaily` ON SCHEDULE EVERY 1 DAY STARTS '2013-08-08 14:49:00' ON COMPLETION NOT PRESERVE ENABLE DO INSERT INTO test(OrgID,valuetime) VALUES(3,NOW())$$

DELIMITER ;

mysql version   V5.5.12

打开开关

SET GLOBAL event_scheduler = 1;
SHOW VARIABLES LIKE 'event_scheduler';

但是关机后会还原为off

永久生效,需在my.ini设置如下

# SERVER SECTION
# ----------------------------------------------------------------------
#
# The following options will be read by the MySQL Server. Make sure that
# you have installed the server correctly (see above) so it reads this
# file.
#
[mysqld]

# The TCP/IP Port the MySQL Server will listen on
port=3306

event_scheduler = 1

重启mysql服务