Most “I need a scheduled task” requests on cPanel hosts get an answer of “use cron.” For shell tasks that’s right. For SQL tasks like nightly archival, expired-row cleanup, or stats aggregation, cron wrapping mysql -e "..." adds an extra hop, an extra credential store, and an extra failure mode. The MySQL Event Scheduler runs SQL on a schedule from inside the database itself — closer to the data, no extra credentials, survives application restarts. cPanel doesn’t enable it by default, and most accounts don’t have grants for it, but the right setup makes it the better tool for SQL-only periodic work.
What’s happening
The Event Scheduler is a MySQL thread that wakes up at intervals and runs events — stored procedure-like objects with a schedule attached. They look like:
CREATE EVENT acmecorp_wp.daily_cleanup
ON SCHEDULE EVERY 1 DAY STARTS '2026-05-20 03:00:00'
DO
DELETE FROM acmecorp_wp.wp_options
WHERE option_name LIKE '%transient%' AND option_name LIKE '%expired%';
The Event Scheduler must be ON globally (SET GLOBAL event_scheduler = ON), and the user creating events needs the EVENT privilege. cPanel’s “set ALL privileges via UI” includes EVENT on recent versions; older builds do not.
Events are useful when:
- The task is purely SQL.
- The schedule should follow the database (e.g., move with restore).
- The task involves a large transaction that’s awkward to wrap in shell.
- You want the schedule visible in
SHOW EVENTSrather than scattered in crontabs.
Events are not useful when:
- The task is mostly file manipulation or external API calls.
- The task needs to run even if MySQL is down (cron survives MySQL outages).
How to verify
mysql -e "SHOW VARIABLES LIKE 'event_scheduler'"
mysql -e "SHOW EVENTS FROM acmecorp_wp"
mysql -e "SELECT EVENT_SCHEMA, EVENT_NAME, STATUS, LAST_EXECUTED FROM information_schema.EVENTS WHERE EVENT_SCHEMA LIKE 'acmecorp\\_%'"
mysql -e "SHOW GRANTS FOR 'acmecorp_app'@'localhost'" | grep -i event
The first shows whether the scheduler is running. The second and third list defined events. The grant check confirms the user can manage events.
The fix
- Enable the Event Scheduler persistently:
Or apply live:/etc/my.cnf.d/cpanel.cnf: [mysqld] event_scheduler = ONSET GLOBAL event_scheduler = ON. Live setting reverts on restart unless config-persisted. - Grant the EVENT privilege to the account user that will create events:
uapi --user=acmecorp Mysql set_privileges_on_database user=acmecorp_app database=acmecorp_app privileges=ALLprivileges=ALLvia uapi includes EVENT on modern cPanel. Verify withSHOW GRANTS. - Create the event:
CREATE EVENT IF NOT EXISTS acmecorp_wp.weekly_options_cleanup ON SCHEDULE EVERY 1 WEEK STARTS '2026-05-25 02:00:00' ON COMPLETION PRESERVE ENABLE COMMENT 'Clean expired transients weekly' DO BEGIN DELETE FROM acmecorp_wp.wp_options WHERE option_name LIKE '_transient_timeout_%' AND option_value < UNIX_TIMESTAMP(); END;ON COMPLETION PRESERVEkeeps the event after first run (default is to drop one-shot events). - Monitor execution:
SELECT EVENT_SCHEMA, EVENT_NAME, LAST_EXECUTED, STATUS FROM information_schema.EVENTS;STATUS = 'ENABLED'means the event will run;'DISABLED'means it’s paused;'SLAVESIDE_DISABLED'means it’s only running on the source in a replication topology. - Backups: include events:
mysqldump --events(separate article on mysqldump options). Without--events, restoring the database loses every event. - Drop or disable events when no longer needed:
DROP EVENT acmecorp_wp.weekly_options_cleanup; ALTER EVENT acmecorp_wp.weekly_options_cleanup DISABLE; - For replicas: by default, events don’t run on the replica (they’re flagged
SLAVESIDE_DISABLED). This prevents double-execution. If the replica is promoted to primary, manually enable events on the new primary.
For environments where SQL-only periodic work is a recurring requirement, Stack Harbor’s environment management team configures the event scheduler with a per-account scheduling convention and monitors event execution history alongside other scheduled work.