Get the App
SLTechnology News&Howtos  ›  Database  › 

How to delete a record before a specified time value in Mysql

Shulou Source: shulou.com Published: 2022-05-31 22:27:15 09月22日 Update

This article introduces how to delete the record before the specified time value in Mysql, the content is very detailed, interested friends can refer to, I hope it can be helpful to you.

First delete the SQL statement recorded 2 days ago (webserver_monitormemory is the table name and time is the time field):

Delete From webserver_monitormemory where DATE (time) BEGIN-> delete From webserver_monitormemory where DATE (time) END-> / / DELIMITER

Create events to customize the stored procedures that execute autodel every day:

CREATE EVENT `event_auto_del_ roomydata` ON SCHEDULE EVERY 1 DAY STARTS '2017-11-20 00 ON COMPLETION NOT PRESERVE ENABLE DO CALL autodel ()

There are 4 ways to turn on event scheduling (scheduler). A key value of 1 or ON means to enable; 0 or OFF means to disable:

SET GLOBAL event_scheduler = 1; SET @ @ global.event_scheduler = 1; SET GLOBAL event_scheduler = ON; SET @ @ global.event_scheduler = ON

There are 3 ways to check whether event scheduling (scheduler) is currently enabled:

SHOW VARIABLES LIKE 'event_scheduler';SELECT @ @ event_scheduler;SHOW PROCESSLIST; customers

Event on and off:

ALTER EVENT event_auto_del_memorydata ON COMPLETION PRESERVE ENABLE; / / enable an event ALTER EVENT event_auto_del_memorydata ON COMPLETION PRESERVE DISABLE; / / close an event

This is the simplest but also the most important. We have to start the timer manually, otherwise it won't work.

ALTER EVENT event_time_clear_data ON COMPLETION PRESERVE ENABLE

In addition, the code to turn off the timer is:

ALTER EVENT event_time_clear_data ON COMPLETION PRESERVE DISABLE

Delete a stored procedure:

DROP PROCEDURE pro_clear_data

Delete Event:

DROP EVENT IF EXISTS event_time_clear_data1 on how to delete the specified time value in the Mysql before the record is shared here, I hope that the above content can be of some help to you, can learn more knowledge. If you think the article is good, you can share it for more people to see.

Tags: Events procedures storage time content timers methods more help scheduling good important code interests fields guys buddies manual articles knowledge Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Information Huawei OPPO Reno vpn MySQL