MySQL入门教程(13)MySQL中的event计划任务
MySQL自身也支持计划任务,可以通过event语句实现周期性的任务,如定时增删数据的操作
一、开启MySQL计划任务
vi my.cnf event_scheduler = 1
二、MySQL计划任务语法
1、在指定时间清空表
use test_database; create event test_event on schedule at timestamp '2020-03-07 12:00:00' do truncate table test_table
2、每天定时清空表
use test_database create event test_event on schedule every 1 day do truncate table test_table
3、5天后开启每天定时清空表的
use test_database create event test_event on schedule every 1 day starts current_timestamp + interval 5 day do truncate table test_table
4、每天定时清空表,5天后停止该任务
use test_database create event test_event on schedule every 1 day ends current_timestamp + interval 5 do truncate table test_table
5、5天后开启每天定时清空表的任务,一个月后停止
use test_database create event test_event on schedule evevy 1 day starts current_timestamp + interval 5 ends current_timestamp + interval 1 month do truncate table test_table
三、查看计划任务
show events \G;
四、修改计划任务的语法和修改删除表一样,使用alter event语句
版权声明:本文章版权归数据库运维网(www.ywdba.cn)所有。如需引用本站内容,请注明来源及作者。
评论