MySQL 创建存储过程 定时器 实现5秒插入一条测试数据

1.建测试表
drop table if EXISTS dajizu;
create table dajizu
(
id INT(20) not null AUTO_INCREMENT,
time datetime not null,
a double not null,
b double not null,
c double not null,
d double not null,
e double not null,
f double not null,
g double not null,
h double not null,
i double not null,
j double not null,
k double not null,
l double not null,
m double not null,
n double not null,
o double not null,
ap double not null,
bp double not null,
cp double not null,
dp double not null,
ep double not null,
fp double not null,
gp double not null,
hp double not null,
ip double not null,
jp double not null,
kp double not null,
lp double not null,
mp double not null,
np double not null,
op double not null,
primary key (id)
)

select * from dajizu;
2.插入一条测试数据
insert dajizu values(0, SYSDATE(), 42.4, 45.3, -0.03, -0.03, 45.8, 45.2, 8592.7, 8592.3, 0.0, 8592.7, 8592.7, 8594.0, 15.2, 49.3, 12.7, 394.2, 3.438, 18102.9, 16.3, 48.9, 12.5, 1.046, 75.6, 75.7, 76.1, 22.0, 75.5, 12.1, 56.4, 6.5);
3.创建存储过程
CREATE PROCEDURE insert_djz_pro()
BEGIN
 insert dajizu values(0, SYSDATE(), 42.4, 45.3, -0.03, -0.03, 45.8, 45.2, 8592.7, 8592.3, 0.0, 8592.7, 8592.7, 8594.0, 15.2, 49.3, 12.7, 394.2, 3.438, 18102.9, 16.3, 48.9, 12.5, 1.046, 75.6, 75.7, 76.1, 22.0, 75.5, 12.1, 56.4, 6.5);
END;
4.创建定时器
create event if not exists insert_djz_event_job 
on schedule every 5 second 
on completion PRESERVE
do call insert_djz_pro();
5.启动定时器
SET GLOBAL event_scheduler = 1;  -- 启动定时器
-- SET GLOBAL event_scheduler = 0;  -- 停止定时器
6.查看定时器状态
SHOW VARIABLES LIKE '%sche%'; -- 查看定时器状态

event_scheduler ON

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

光于前裕于后

您的打赏将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值