首页 技术 正文
技术 2022年11月8日
0 收藏 920 点赞 1,960 浏览 1003 个字

1. 查看数据库的event功能是否开启,在MySql中event默认是关闭的,需要查看并且要确保event处于开启状态

sql:show VARIABLES LIKE ‘%sche%’;

如果event_scheduler显示为off或者0说明是关闭的,这时我们需要手动打开定时器

sql:SET GLOBAL event_scheduler = 1;

这时再输入

sql:show VARIABLES LIKE ‘%sche%’;

event_scheduler就应该是ON或这是1了;即可以进行后面的操作。

2. 创建测试表

create table user1

(

id int(11) not null auto_increment primary key,

username varcher(15) not null

)

3. 创建event要调用的存储过程user1_test

create procedure user1_test()

begin

#为方便查看测试结果,推荐使用now()函数获取当前时间进行插入

insert into user1(username ) values(now());

end

4. 创建事件user1_event

create event user1_event
#这句话是设置时间多长时间执行一次(本设置是1S一次)
on schedule every 1 second
on completion preserve disable
#这个是指定要执行的代码块,在上面已经定义过了(即为3.创建的储存过程)
do call user1_test();

5. 开启事件user1_event,因为在创建之后是默认关闭的

#开启

alter event user1_event on completion preserve enable;

#关闭(关闭时间自行控制,推荐开启约10S左右关闭,这样可以很直观的看到执行后的数据)

alter event user1_event on completion preserve disable;

6. 重头戏开始了,查看你的数据

1 2019-06-10 10:35:56
22019-06-10 10:35:57
32019-06-10 10:35:58
42019-06-10 10:35:59
52019-06-10 10:36:00

是不是多出了好多条数据,恭喜你成功了!

参考:https://blog.csdn.net/ICanForYou/article/details/88957567

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,490
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,905
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,738
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,491
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:8,129
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:5,292