1. Insert the user2 table query data into the user table in batches--stored procedure
DELIMITER $$ CREATE PROCEDURE `存储过程名称`() BEGIN INSERT INTO `user` ( `userid`, `username`, `userage` ) SELECT `userid2` AS userid, `username2` AS username, `userage2` AS userage FROM `user2` WHERE userid2 < 50; END$$ DELIMITER ;
2. Create a timer
#创建定时器 create event if not exists 定时器名称 ON SCHEDULE EVERY 1 DAY STARTS DATE_ADD(DATE_ADD(CURDATE(), INTERVAL 1 DAY), INTERVAL 1 HOUR) --每天一点执行 on completion PRESERVE do call 存储过程名称();
3. Start the timer
#启动定时器 SET GLOBAL event_scheduler = 1; #停止定时器 SET GLOBAL event_scheduler = 0;
4. Turn on timed events (it is turned on by default. If the timer is turned on and the stored procedure is not executed, the event is not turned on)
#开启事件 ALTER EVENT 定时器名称 ON COMPLETION PRESERVE ENABLE; #关闭事件 ALTER EVENT 定时器名称 ON COMPLETION PRESERVE DISABLE;
5. Check the status of the timer
#查看定时器状态 SHOW VARIABLES LIKE '%sche%';
You can use the sqlyong visualization tool to modify stored procedures or timers.