Mysql event Scheduler

August 5, 2013 | Rishabh Agrawal | General

Hello guys, It’s being a long time when i havn’t written any blog. Now i will like to introduce a simple but very powerful concept of the mysql. Suppose you want to store a data according to the daily basis but after some days that data is not required to you. So you definitely want to delete that particular data but how you do that? This is the biggest question? what sort of coding should i do that it run after some event. So i will like to introduce a concept of mysql i.e. event schedule.

Event Scheduler: Events are executed by a special event scheduler thread; when we refer to the Event Scheduler, we actually refer to this thread.

DATABASE

// first of all create a table

create table counter(
id int(11) auto_increment,
username varchar(100),
created_at timestamp default current_timestamp,
primary key(id)
)

How to enable the event Scheduler?
Go to the MySql Event Scheduler and execute the following command.

//to enable the event scheduler
SET GLOBAL event_scheduler = ON;

Create a Event

create event insertUsername
on schedule every 1 second
Do
insert into counter(username)values('pradeep');

Output

 

still the process going on…. every second u get another value…

If you want to insert a value every 10 days later

create event insertUsername
on schedule every 10 day
Do
insert into counter(username)values('pradeep');

and so on.
Thus this small event scheduler is basically used where you have to fire a query at a particular time. For example if you want to send a push notification to a user at a particular time (i.e. around 12.0.0 clock) then you can create the schedule for that query to fire on particular time.

Alter an Event
If you want to make the changes in the event then you can make changes in the event by alter command

alter insertUsername
ON SCHEDULE EVERY 1 HOUR
STARTS TIMESTAMP + 1 HOUR

Show Event
If you want to show all the events running on particular database then use the below command

Show Events;

 

Drop an Event
If you want to drop the events running on particular database then use the below command

drop event insertUsername;

THE AUTHORRishabh Agrawal

Rishabh Agrawal is the founder of Creatiosoft, a company focused on creating high-quality software for the iGaming industry, specialising in poker and card games. With years of experience, Rishabh is dedicated to delivering engaging and user-friendly gaming experiences. Through this blog, he shares his passion and insights to help readers understand the latest trends and advancements in iGaming.

Recent Posts

The Future of Mobile Gaming: What to Expect in the Next 5 Years

Over the years, mobile gaming has seen amazing development and innovation utilized by the game development company in India. It…
06 Jun 2023 Rishabh Agrawal

How Do I Get Started With NFT Gaming?

The popularity of the NFT game has created a different fan base. There was a time when games were a…
18 Jul 2022 Rishabh Agrawal

What Are The Top Trends in NFT Marketplace 2022?

The NFTs are the new engaging and revolutionary technology across the globe. Though, these non-fungible tokens appeared for the first…
09 Jun 2022 Rishabh Agrawal