Periodically clean up the data of a table in the mysql remote database in the Windows environment (using the Navicat tool)
Reference link: https://blog.csdn.net/tongluren381/article/details/106523796/Preparing mysql does not enable scheduled task execution
by
default, you can enter in Navicat:
show variables like 'event_scheduler';
If it is ON, it means that you don’t need to worry about it and you can start cleaning directly. If it is OFF, you need to open it first.
Method 1 : Execute set global event_scheduler=1
; this method is equivalent to a one-off, and it will fail after restarting, so it is not recommended to use.
Method 2 : Modify the mysql configuration file my.ini (in Windows environment) or my.cnf (in Linux environment), and add a line under [mysqld]:
event_scheduler=ON
Then restart the mysql service:service mysqld restart
start cleaning
1. Select the database and click "Event".
2. Click "New Event".
3. Enter the sql statement to be executed in the definition. For example, delete data created 7 days ago (for example, today, June 29, after the command is executed, the data before June 22 will be deleted, including June 22):
delete from table where Date(create_time) <= DATE(DATE_SUB(NOW(),INTERVAL 7 DAY))
Note : The case here must be entered strictly according to the specification. I have an error because the following DATE is not strictly capitalized.
4. Fill in the scheduled task execution cycle in the "Plan" section, and enter the start time.
5. After all settings are completed, click the "Save" button.
6. Set the time name of the scheduled task (custom).
Note : Click on the event, there are options below to directly set the status of the scheduled task ( ENABLE
on; DISABLE
off)