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.
Asked
Active
Viewed 1.2k times
4 Answers
15
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();

Talha Ahmed Khan
- 15,043
- 10
- 42
- 49
-
Thanks a lot .... can you please say that how we run this query without calling from any external language. – John Christy Dec 14 '12 at 05:14
-
its my mistake if we create an event in MySQL it will run automatically rit. Thanks – John Christy Dec 14 '12 at 05:23
3
you can achieve with mysql event scheduler--
http://dev.mysql.com/doc/refman/5.1/en/events.html
detail blog: http://goo.gl/6Hzjvg

Suresh Kamrushi
- 15,627
- 13
- 75
- 90
0
Create an event like below
CREATE EVENT e_daily
ON SCHEDULE
EVERY 1 DAY
DO
BEGIN
DELETE FROM tableA WHERE DATE(`yourtimestamp`) <(CURDATE() - INTERVAL 6 MONTHS);
END

cjds
- 8,268
- 10
- 49
- 84
0
You can also write a script that processes your data in Python, Perl, PHP, etc.
After that, simply setup cron entry using crontab -e
and add following line:
0 23 * * * /path/to/my/script.pl 2>&1 >/dev/null
If you don't specify 2>&1 >/dev/null
, you will get email with execution results.

mvp
- 111,019
- 13
- 122
- 148