Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

A simple method for mysql to delete expired data records at regular intervals

2025-04-06 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

1. After connecting and logging in to MySQL, check whether MySQL has enabled the event feature:

Command: show variables like'% sc%'

It was found that event_sheduler was closed by OFF.

two。 Open event_scheuler:

Temporarily start (expire after the mysql service restarts)

SET GLOBAL event_scheduler = ON; SET GLOBAL event_scheduler = 1;-0 means off

Permanently open

Add the following to the [mysqld] section of my.cnf, and then restart mysql (mysql restart command: service mysqld restart)

Event_scheduler=ON

3. Create an event. Here is an example of regularly deleting data in the wififlows table that has expired for 2 minutes every 5 seconds:

Create event e_delete_wififlows on schedule every 5 second do delete from wififlows where timestamp < (CURRENT_TIMESTAMP () + INTERVAL-2 MINUTE)

If this event exists in advance, you can delete it using the following command:

Drop event if exists e_delete_wififlows

Then use show events; to view the events that exist

4. Enable event:

Alter event e_del_wififlows on completion preserve enable

5. Shutdown event:

Alter event e_del_wififlowa on completion preserve disable

The above mysql regularly delete expired data records of the simple way is the editor to share with you all the content, I hope to give you a reference, but also hope that you support more.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report