Search code examples
mysqlschedulemysql-event

MySQL gives error in creating MySQL-Events


I am trying to create one MySQL event which updates the table at every midnight. My query is like this:

CREATE EVENT postdetails_change_status 

ON SCHEDULE EVERY 1 DAY STARTS '2014-04-21 00:00:00'

DO BEGIN

    UPDATE postdetails SET status = 'completed' WHERE DeleteDate < CURDATE();

END;

This gives me error likeenter image description here

But when I run this update query normally, it works perfectly. Please help.

Reference: http://www.sitepoint.com/how-to-create-mysql-events/


Solution

  • Your script is correct but just change delimiter before script execution. try below:

    delimiter |
    
    CREATE EVENT postdetails_change_status 
    
    ON SCHEDULE EVERY 1 DAY STARTS '2014-04-21 00:00:00'
    
    DO BEGIN
    
        UPDATE postdetails SET status = 'completed' WHERE DeleteDate < CURDATE();
    
    END |
    
    delimiter ;