A simple method for mysql to delete expired data records at regular intervals
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.