mysql Schedule Event每5分钟一次 [英] mysql Schedule Event every 5 minutes

查看:713
本文介绍了mysql Schedule Event每5分钟一次的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下脚本.脚本可以运行,但是我想要的是在壁钟时间之后每5分钟运行一次.这意味着它应在挂钟时间之后的5分钟间隔内的5、10、15 ...处运行.我可以估算出运行结果的时间是10到30秒.有没有办法使它更接近5分钟的标记?谢谢.

I have the following script. The scripts runs but what i want is for it to run every 5 minutes following the wall clock time. Meaning it should run at 5, 10, 15 ... following the wall clock time at 5 minitues interval. What I can gauge for the result of the run is that the time is 10 - 30 seconds off. Is there a way to get it closer to the 5 minutues mark?. Thanks.

CREATE DEFINER=`root`@`%` 
EVENT `run_event` 
ON SCHEDULE EVERY 5 MINUTE STARTS '2016-04-06 00:00:00' 
ON COMPLETION NOT PRESERVE ENABLE 
DO CALL my_procedure

推荐答案

您的配置似乎正确.事件的时间安排不是非常精确,而是合理的,以至于不应过半分钟.

Your configuration seems correct. The timing of events is not extremely precise, but it is reasonably precise -- enough that it shouldn't be half a minute off.

事件疑难解答的一个有趣的技巧是从事件内部发出警告.由于没有可以向其发送警告的客户端,因此该警告将写入MySQL错误日志.这应该在MySQL 5.5及更高版本中起作用:

One interesting hack for event troubleshooting is to throw a warning from within the event. Since there is no client to which the warning can be sent, the warning is written to the MySQL error log. This should work in MySQL 5.5 and up:

DELIMITER $$

DROP EVENT IF EXISTS run_event $$

CREATE DEFINER=`root`@`%` 
EVENT `run_event` 
ON SCHEDULE EVERY 5 MINUTE STARTS '2016-04-06 00:00:00' 
ON COMPLETION NOT PRESERVE ENABLE
DO 
BEGIN
  SIGNAL SQLSTATE '01000' SET MESSAGE_TEXT = 'run_event started';
  CALL my_procedure;
  SIGNAL SQLSTATE '01000' SET MESSAGE_TEXT = 'run_event finished';
END $$

自从我使用它已经有一段时间了,但是我相信警告将立即写入错误日志,并且不会缓冲直到事件结束.

It's been a while since I used this, but I believe the warnings will be written to the error log immediately, and not buffered until the event is finished.

这篇关于mysql Schedule Event每5分钟一次的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆