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

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

2025-01-21 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)05/31 Report--

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.

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