The MariaDB Event Scheduler lets you run SQL statements automatically at predefined times or intervals.
Event Scheduler keeps logic close to data, runs inside the DB engine, respects transactions, and works cross-platform—no OS-level access required.
Run SET GLOBAL event_scheduler = ON;
once. Add event_scheduler=ON
to my.cnf
for permanence.
Use CREATE EVENT
plus a timing clause (AT
or EVERY
) and a SQL body. Add ON COMPLETION PRESERVE
to keep one-time events.
CREATE EVENT daily_old_orders_cleanupON SCHEDULE EVERY 1 DAY STARTS CURRENT_DATE + INTERVAL 1 DAYDO DELETE FROM Orders WHERE order_date < CURRENT_DATE - INTERVAL 90 DAY;
Yes. Use ALTER EVENT ... ON SCHEDULE ...
to change timing, or ALTER EVENT ... DISABLE
to pause execution.
Query INFORMATION_SCHEMA.EVENTS
to see last and next run times, status, SQL body, and execution counts.
Set a DEFINER
with the minimum required privileges to limit risk. Pair with SQL SECURITY DEFINER
for predictable permissions.
Wrap body inside a procedure that writes to a JobLog
table capturing event_name
, started_at
, rows_affected
, and error_message
.
Yes, as long as event_scheduler=ON
is set in my.cnf
. Event definitions are stored in the mysql
database.
Wrap them inside a stored procedure and call the procedure inside DO
. This keeps the job definition readable and transactional.
Use DROP EVENT IF EXISTS event_name;
. Consider logging execution history before deletion.