Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to force an event to execute in MySQL

Tags:

mysql

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.

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.

like image 467
user55417 Avatar asked May 15 '09 21:05

user55417


People also ask

What is a MySQL event?

A MySQL Event is nothing but a task that execute at a particular schedule. An event can contain one or more MySQL statements these statements are stored in the databases and gets executed at the specified schedule. The CREATE EVENT statement is used to create and schedule an MYSQL event.

How to execute scheduled events in MySQL using event scheduler?

In order to execute scheduled events in MySQL, we have to check the value of the global system variable event_sheduler. This enables us to determine the status of the special event scheduler thread which is responsible to execute Events. The following command will show you whether the scheduler is running or not.

How do I drop an existing event in MySQL?

MySQL DROP EVENT Statement To remove an existing event, you use the DROP EVENT statement as follows: DROP EVENT [ IF EXIST] event_name; Code language: SQL (Structured Query Language) (sql)

How do I create an event in SQL?

The keywords CREATE EVENT plus an event name, which uniquely identifies the event in a database schema. An ON SCHEDULE clause, which determines when and how often the event executes. A DO clause, which contains the SQL statement to be executed by an event. The previous statement creates an event named myevent.


1 Answers

  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.
like image 163
Evert Avatar answered Oct 12 '22 11:10

Evert