In the actual project of creating a MySQL scheduled task, you only want to save the records of the last seven days in the MySQL database. It is troublesome and inefficient to delete the records by using SQL commands, event sched provided by Mysql can be easily implemented. The specific steps for www.2cto.com are as follows: 1: log ON to the MySQL console as a Super User # mysql-uroot 2: Enable event_scheduler (disabled by default) mysql> set global event_scheduler = ON; 3: CREATE an EVENT (delete_old_record in this example) www.2cto.com mysql> create event delete_old_record on schedule every 1 day starts now () DO -- delete the old records of demo_partition table delete from demo_partition table WHERE datediff (NOW (), log_timestamp)> = 7; -- delete the old records of puma_2_table Delete from demo_2_table WHERE datediff (NOW (), log_timestamp)> = 7; -- delete the old records of puma_3_table delete from demo_3_table WHERE datediff (NOW (), log_timestamp)> = 7; -- delete the old records of puma_4_table delete from demo_4_table WHERE datediff (NOW (), log_timestamp)> = 7; 4: Start the created EVENT mysql> alter event delete_old_record ENABLE; after that, the database executes the jobs after DO every day to delete the records of each table 7 days ago. Appendix: The create event format is as follows: CREATE [DEFINER = {user | CURRENT_USER}] EVENT [if not exists] event_name on schedule schedule [on completion [NOT] PRESERVE] [ENABLE | disable on slave] [COMMENT' comment '] DO event_body; schedule: AT timestamp [+ INTERVAL interval]... | EVERY interval [STARTS timestamp [+ INTERVAL interval]...] [ENDS timestamp [+ INTERVAL interval]...] interval: quantity {YEAR | QUARTER | MONTH | DAY | HOUR | MINUTE | WEEK | SECOND | YEAR_MONTH | DAY_HOUR | DAY_MINUTE | DAY_SECOND | HOUR_MINUTE | HOUR_SECOND | MINUTE_SECOND}