mysql技术任务_MySQL基础教程(13)MySQL计划任务

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语句

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值