如何强制事件在 MySQL 中执行

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/870883/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 13:17:02  来源:igfitidea点击:

How to force an event to execute in MySQL

mysql

提问by user55417

I am trying to write an automated test script for testing a MySQL Event that I created, and I am wondering if there is a way to execute some kind of command to force the Event to execute immediately. The Event is set to run daily at midnight, but I don't want the automated test script to have to wait for the Event to trigger.

我正在尝试编写一个自动化测试脚本来测试我创建的 MySQL 事件,我想知道是否有办法执行某种命令来强制事件立即执行。事件设置为每天午夜运行,但我不希望自动化测试脚本必须等待事件触发。

One way I can think of is to ALTER the Event to have it execute one-time 5 seconds into the future, but I'd like to know if there is a more elegant way to do get it to execute.

我能想到的一种方法是改变事件,让它在未来 5 秒内执行一次,但我想知道是否有更优雅的方法来执行它。

回答by Evert

  1. Move all the code within the event into a stored procedure
  2. Make the event only call the stored procedure
  3. Test the stored procedure with the CALL syntax.
  1. 将事件中的所有代码移动到存储过程中
  2. 使事件只调用存储过程
  3. 使用 CALL 语法测试存储过程。

回答by KM.

if it is based on the system time, change that, and see if your event fires, then change the system time back.

如果它基于系统时间,请更改它,然后查看您的事件是否触发,然后将系统时间更改回来。

回答by Yaniv Peretz

Another 'proxy' solution is schedule it ver soon, for example: ON SCHEDULE EVERY 10 SECOND (or 1 sec, depends how long in the run time of the event). you could later drop the event.

另一个“代理”解决方案是尽快安排它,例如:ON SCHEDULE EVERY 10 SECOND(或 1 秒,取决于事件的运行时间)。您可以稍后删除该事件。