Run a periodic cleanup task inside MySQL.

Section: triggers and events

Create a scheduled event

sql
sql
CREATE EVENT ev_purge_expired_sessions
ON SCHEDULE EVERY 1 DAY
DO
  DELETE FROM sessions WHERE expires_at < NOW();
Explanation

The event scheduler can automate recurring maintenance tasks inside the database.

Learn the surrounding workflow

Compare similar commands or jump into common fixes when this command is part of a bigger troubleshooting path.

Related commands

Same sheet · prioritizing triggers and events
Drop a trigger
Remove a trigger definition.
OpenIn sheetsqlsame section
Create a BEFORE INSERT trigger
Normalize row data before insert.
OpenIn sheetsqlsame section
List triggers
Display triggers defined in the current schema.
OpenIn sheetsqlsame section
List events in a database
Inspect scheduled events.
OpenIn sheetsqlsame section
Change the statement delimiter
Define routines containing semicolons.
Call a stored procedure
Execute a procedure with input arguments.