1. Enable the Event Scheduler
You can enable it temporarily or permanently.
-
Temporarily (until MySQL restarts):
-
Check if it’s enabled:
-
Permanently (edit MySQL config file):
Add this line to your my.cnf (Linux) or my.ini (Windows) file under [mysqld] section:
Then restart MySQL server.
2. Disable the Event Scheduler
-
Temporarily:
-
Permanently: Remove or set
event_scheduler=OFFin your MySQL config file and restart the server.
3. Create, Show, and Drop Events
-
Create an event (example: event runs every day):
-
Show events:
-
Drop (delete) an event:
MySQL Event Scheduler for Last Day of Month Reset
Explanation:
-
LAST_DAY(CURDATE())returns the last day of the current month. -
We compare it with
CURDATE()(today). -
If they are equal, it's the last day of the month.
-
Then
actual_lead_countis reset to zero for all staffs.
Important:
-
Make sure the MySQL event scheduler is enabled (see previous message).
-
Adjust the
STARTStime for when you want this event to first run (e.g., at midnight)
Step 1: Enable Event Scheduler in MySQL on cPanel
Important: The MySQL event scheduler setting is usually controlled at the server level, so you might not be able to enable or disable it directly through cPanel unless your hosting provider allows it.
-
Check if Event Scheduler is enabled:
-
Log in to cPanel.
-
Open phpMyAdmin.
-
Select your database.
-
Go to the SQL tab and run:
If it says OFF, then the scheduler is disabled.
-
Enable it temporarily (if your user permissions allow):
Run:
If you get a permission error, then you will need to contact your hosting provider to enable it.
Step 2: Manage Events in phpMyAdmin (within cPanel)
-
To view existing events:
-
In phpMyAdmin, click your database.
-
Click on the Events tab (usually next to Tables, Views, etc.).
-
If you don’t see the Events tab, your user permissions or MySQL version might not support events.
-
-
You will see a list of scheduled events.
-
-
To delete (drop) an event:
-
In the Events tab, select the event you want to remove.
-
Click Drop to delete it.
-
-
To create or edit an event:
-
You can use the SQL tab and write an event creation query, for example:
-