Autorunning Query in mysql

John Christy picture John Christy · Dec 14, 2012 · Viewed 10.3k times · Source

Is it possible to make a stored procedure that run every night 11 pm , check in table if any record is modified for last six month, If some record is modified for last six month I have to delete it from table. This has to run automatically without use of any external language.

Answer

Talha Ahmed Khan picture Talha Ahmed Khan · Dec 14, 2012
CREATE EVENT IF NOT EXISTS `my_old_data_cleaner_event`
ON SCHEDULE EVERY 23 DAY_HOUR
COMMENT 'Clean up Service Start at 11:00PM daily!'
DO DELETE FROM my_table WHERE created_date < (NOW() - INTERVAL 1 MONTH);

OR for Stored Procedure.

CREATE EVENT IF NOT EXISTS `my_old_data_cleaner_event`
ON SCHEDULE EVERY 23 DAY_HOUR
DO CALL my_sp_cleanup_old_data();