1. Background As the project's business continues to move forward, it is inevitable that the number of database tables will become larger and larger, constantly occupying hard disk space. Even a larger space cannot support the growth of business, so it is necessary to delete unnecessary data regularly. In our project, due to the lack of data cleaning, the space occupied by a table reached as much as 4G. Just think how scary it is... Here we introduce how to use MySQL to create a timer Event to regularly clear previous unnecessary events. 2. Content #1. Create a stored procedure for events to call delimiter// drop procedure if exists middle_proce// create procedure middle_proce() begin DELETE FROM jg_bj_comit_log WHERE comit_time < SUBDATE(NOW(),INTERVAL 2 MONTH); optimize table jg_bj_comit_log; DELETE FROM jg_bj_order_create WHERE created_on < SUBDATE(NOW(),INTERVAL 3 MONTH); optimize table jg_bj_order_create; DELETE FROM jg_bj_order_match WHERE created_on < SUBDATE(NOW(),INTERVAL 3 MONTH); optimize table jg_bj_order_match; DELETE FROM jg_bj_order_cancel WHERE created_on < SUBDATE(NOW(),INTERVAL 3 MONTH); optimize table jg_bj_order_cancel; DELETE FROM jg_bj_operate_arrive WHERE created_on < SUBDATE(NOW(),INTERVAL 3 MONTH); optimize table jg_bj_operate_arrive; DELETE FROM jg_bj_operate_depart WHERE created_on < SUBDATE(NOW(),INTERVAL 3 MONTH); optimize table jg_bj_operate_depart; DELETE FROM jg_bj_operate_login WHERE created_on < SUBDATE(NOW(),INTERVAL 3 MONTH); optimize table jg_bj_operate_login; DELETE FROM jg_bj_operate_logout WHERE created_on < SUBDATE(NOW(),INTERVAL 3 MONTH); optimize table jg_bj_operate_logout; DELETE FROM jg_bj_operate_pay WHERE created_on < SUBDATE(NOW(),INTERVAL 3 MONTH); optimize table jg_bj_operate_pay; DELETE FROM jg_bj_position_driver WHERE created_on < SUBDATE(NOW(),INTERVAL 3 MONTH); optimize table jg_bj_position_driver; DELETE FROM jg_bj_position_vehicle WHERE created_on < SUBDATE(NOW(),INTERVAL 3 MONTH); optimize table jg_bj_position_vehicle; DELETE FROM jg_bj_rated_passenger WHERE created_on < SUBDATE(NOW(),INTERVAL 3 MONTH); optimize table jg_bj_rated_passenger; end// delimiter; #2. Enable event (for the timing to work, the MySQL constant GLOBAL event_scheduler must be on or 1) show variables like 'event_scheduler' set global event_scheduler='on' #3、Create Evnet event drop event if exists middle_event; create event middle_event on schedule every 1 DAY STARTS '2017-12-05 00:00:01' on completion preserve ENABLE do call middle_proce(); #4、Open Event alter event middle_event on completion preserve enable; #5. Close Event event alter event middle_event on completion preserve disable; The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM. You may also be interested in:
|
<<: Detailed explanation of the use of Vue3 state management
>>: How to install ionCube extension using pagoda
This article uses examples to illustrate the usag...
I believe everyone is familiar with the trashcan,...
Due to hardware reasons, the machines may not kee...
Table of contents Preface 1. First completely uni...
Recently, during the development process, the MyS...
Table of contents 1. Introduction 2. Deployment E...
Preface In the past, the company used the 5.7 ser...
In this tutorial, we use the latest MySQL communi...
Table of contents MAH 1. Introduction to MAH Arch...
When we want to use a new CSS feature, we always ...
Many times when we process file uploads, such as ...
Here are two ways to install MySQL under Linux: y...
Using provide+inject combination in Vue First you...
Table of contents View all storage engines InnoDB...
Basically all e-commerce projects have the functi...