This article is half-done without your Comment! *** Please share your thoughts via Comment ***
In this post, I am sharing one of important and basic article about, How to create a SQL Job or scheduler in the MySQL Database Server.
For scheduling the database tasks are very common exercise for all Database Developers and Database Administrators.
The SQL Agent is available in SQL Server and The PG Agent is available in PostgreSQL.
If you want to schedule your database task in MySQL, You should use default Event Scheduler of MySQL Database Server.
You can define event using CREATE EVENT statement and It requires the EVENT privilege for the schema in which the event is to be created.
It might also require the SUPER privilege.
You can access below full demonstration step by step.
Create a sample table:
1 2 3 4 5 |
CREATE TABLE tbl_Students ( StudID INT ,StudName VARCHAR(50) ); |
1 |
SET GLOBAL event_scheduler = ON; |
1 |
SET GLOBAL event_scheduler = ON; |
1 2 |
SHOW PROCESSLIST; -- event_scheduler User is running under command "Daemon" |
1 2 3 4 5 |
CREATE EVENT Eve_tbl_Students_Temp_Insert ON SCHEDULE EVERY 1 MINUTE DO INSERT INTO tbl_Students VALUES (1,'Anvesh'); |
1 2 3 4 |
CREATE EVENT Eve_tbl_Students_Temp_Delete ON SCHEDULE AT CURRENT_TIMESTAMP + INTERVAL 1 MINUTE DO DELETE FROM tbl_Students; |
1 |
ALTER EVENT Eve_tbl_Students_Temp_Insert ON SCHEDULE EVERY 2 MINUTE; |
1 2 |
ALTER EVENT Eve_tbl_Students_Temp_Insert DISABLE; ALTER EVENT Eve_tbl_Students_Temp_Delete DISABLE; |
1 2 |
DROP EVENT Eve_tbl_Students_Temp_Insert; DROP EVENT Eve_tbl_Students_Temp_Delete; |
Leave a Reply