mysql trigger to delete old data 1

mysql trigger to delete old data

SET GLdelimiter //
create event if not exists clean_old_records
on schedule every 1 week
do
begin
 delete from your_table_name 
 where 
 Timestamp < date_sub(curdate(),interval 1 month) ;
end; //
delimiter ;OBAL event_scheduler = ON;

Here is what the above code is Doing:
1. It's creating an event that will run every week.
2. It's deleting records that are older than 1 month.
3. It's turning on the event scheduler.

You can change the interval to whatever you want.

Similar Posts