MySQL Tutorial
Introduction Installation of MySQL Getting MySQL server information RDBMS Concepts Data Definition Language Data types Managing Databases Managing Tables Managing Views Inserting records in a table Updating records in a table Deleting records from a table Retrieving Records Data Control Language Variables in MySQL Procedures in MySQL Built-In functions in MySQL User Defined functions in MySQL Triggers in MySQL Cursors in MySQL Transaction control Event scheduler Tuning MySQL Server Performance Managing users Importing and Exporting data Database Testing Workbench PHPMyAdminEvent scheduler in MySQL
Events are used to execute some SQL code at specified time just like windows scheduler or cron jobs in Linux. Here are the steps to create events.- Start the scheduler
- Create Event
- View the active events from the database.
SET GLOBAL event_scheduler = ON;
Once you do that, you will see that event_scheduler process is started using below statement.
SHOW PROCESSLIST;
Next you need to create the event as shown in below example. Here we are first dropping the event and then creating new one with name MyEvent. This event starts now and ends after 1 minute repeating each 15 seconds. After every 15 seconds, it will insert a record in Table – dup.
Drop event if exists MyEvent;
CREATE EVENT MyEvent
ON SCHEDULE EVERY 15 second
STARTS now()
ENDS now() + INTERVAL 1 minute
DO
INSERT INTO dup VALUES(‘Testing Event’,now());
You can view all active events using below query.
SHOW EVENTS FROM Deals;
In case, your events are not working as expected, ensure that event_scheduler is ON. You can also check the server logs for any errors.Web development and Automation testing
solutions delivered!!