Event schedulers are a way of scheduling Database jobs in Mariadb/MYSQL databases, it is similar to job schedulers used in Oracle and other databases.
There are times where we need to run certain reports or run queries at specified times, these can be accomplished using event schedulers in MariaDB database.
Before scheduling events we need to turn ON event_scheduler variable, we can check the current status using below command :
show Variables like "event_scheduler";
output :
---------------------------------
Variable_Name | Value
---------------------------------
event_scheduler | ON
---------------------------------
It is visible above that scheduler is turned ON, and hence we can proceed with scheduling jobs.
Create event 'test' On schedule every 24 hours starts 'Date' ENDS 'Date' On Completion Preserve Enable DO
Begin
select * from test.test1;
We create an event named Test scheduled to run every 24 hours at a specified time with start and END date. If we don't specify On completion Preserve the event will be dropped from the database and need to recreate, hence it is important ot mention On completion Preserve.
Event is also enabled using the Enable clause.
To check event scheduled we can query information_schema.events table, that will provide information about currently scheduled events and their execution statistics.
More details regarding the syntax and scheduling can be found in mariadb website.
There are times where we need to run certain reports or run queries at specified times, these can be accomplished using event schedulers in MariaDB database.
Before scheduling events we need to turn ON event_scheduler variable, we can check the current status using below command :
show Variables like "event_scheduler";
output :
---------------------------------
Variable_Name | Value
---------------------------------
event_scheduler | ON
---------------------------------
It is visible above that scheduler is turned ON, and hence we can proceed with scheduling jobs.
If the event scheduler is not running and
event_scheduler
has been set to OFF
, use:SET GLOBAL event_scheduler = ON;
Create event syntax can be studied in detail on Mariadb/MYSQL website, i will create a simple event to demonstrate here.Create event 'test' On schedule every 24 hours starts 'Date' ENDS 'Date' On Completion Preserve Enable DO
Begin
select * from test.test1;
We create an event named Test scheduled to run every 24 hours at a specified time with start and END date. If we don't specify On completion Preserve the event will be dropped from the database and need to recreate, hence it is important ot mention On completion Preserve.
Event is also enabled using the Enable clause.
To check event scheduled we can query information_schema.events table, that will provide information about currently scheduled events and their execution statistics.
More details regarding the syntax and scheduling can be found in mariadb website.