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
Since my development environment is to install Ce...
The div+css layout to achieve 2-end alignment is ...
What are XHTML tags? XHTML tag elements are the b...
This article shares the specific code of Vue to i...
Problems: After adding the -v parameter to docker...
Sophie Hardach Clyde Quay Wharf 37 East Soapbox Rx...
1.1 Introduction By enabling the slow query log, ...
Table of contents Overview Code Implementation Si...
1. Cause: The effect after the subbox is set to f...
If you directly set the width attribute to the sty...
This article uses examples to explain the concept...
1. MySQL User Management [Example 1.1] Log in to ...
1 Introduction Apache Storm is a free, open sourc...
Table of contents 1. Software and system image 2....
Table of contents Preface 1. Install scp2 2. Conf...