joedborg
joedborg

Reputation: 18353

Can't schedule a stored procedure in MySQL

What am I doing wrong here? I just want procedure to be run daily.

CREATE EVENT my_event
ON SCHEDULE EVERY 1 DAY
DO
BEGIN
CALL my_procedure("foo");
END $$

Or

CREATE EVENT my_event
ON SCHEDULE EVERY 1 DAY
DO CALL my_procedure("foo");

And get

ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'EVENT my_event
ON SCHEDULE EVERY 1 DAY
DO
BEGIN
CALL my_procedure' at line 1

Upvotes: 1

Views: 2114

Answers (2)

Jarede
Jarede

Reputation: 3488

If you are using windows, then

How to schedule a mysql stored procedure in windows?

the comments to this question show how to create a batch file to be run as a scheduled job that will call the procedure.

Upvotes: 0

Naveen Kumar
Naveen Kumar

Reputation: 4601

Try this query

Check if event scheduler is off

select @@event_scheduler

if its off you have to toogle it to on

SET @@global.event_scheduler = ON;

if the mysql server shutsdown the event scheduler would again turn off

Upvotes: 1

Related Questions