MySQL Event Scheduler

Event Scheduler

If the event scheduler is not enabled, we can set the event_scheduler system variable to enable and start it:
SET GLOBAL event_scheduler = ON;
To disable and stop the event scheduler thread, you set event_scheduler system variable to OFF:
SET GLOBAL event_scheduler = OFF;

Create one time execution event

CREATE EVENT IF NOT EXISTS event_01
ON SCHEDULE AT CURRENT_TIMESTAMP + INTERVAL 20 SECOND
DO
INSERT INTO tbl_books
(book_name, book_author, book_publication, book_description)
VALUES ('Book 110', 'Author 110', 'Publication 110', 'Description
110')

Create recurring event

CREATE EVENT IF NOT EXISTS event_11
ON SCHEDULE EVERY 1 SECOND
STARTS CURRENT_TIMESTAMP
ENDS CURRENT_TIMESTAMP + INTERVAL 20 SECOND
DO
INSERT into tbl_books (book_name, book_author,
book_publication, book_description)
VALUES ('Book 1', "Author 1", "Publication 1", "Description
1")

Recurring event with infinite scheduled time

CREATE EVENT IF NOT EXISTS event_15
ON SCHEDULE EVERY 3 SECOND
STARTS CURRENT_TIMESTAMP + INTERVAL 5 SECOND
DO
INSERT INTO tbl_books (book_name, book_author, book_publication,
book_description)
VALUES ('Book 1', 'Author 1', 'Publication 1', 'Description 1')

Labels: ,

© copyright-2020 Rejaul