Recently wrote a small project, need to regularly query data and add to another table. The idea is as follows:
First, create a stored procedure
Second, create a transaction to periodically execute a stored procedure
(This is the way of thinking, simple and clear)
Looking at the first process, the following I will write in the simplest SQL:
1. Create a stored procedure
CREATE PROCEDURE up_con_outTime()
BEGIN
select * from student;
END;
2. Create a transaction to periodically execute a stored procedure
--DEFINER=`root`@`localhost` 1.%允许来自任何ip的连接2.localhost允许本机的连接
CREATE DEFINER=`root`@`localhost` EVENT up_con_outTime_event
ON SCHEDULE EVERY 1 MINUTE STARTS '2018-10-13 09:57:59'
ON COMPLETION NOT PRESERVE ENABLE
DO CALL up_con_outTime
The stored procedure is also good, and the transaction is good. The next step is to execute!
1. Open Event
Check if the event scheduler is enabled >>> show variables like '% sche%';
Open event >>> set GLOBAL event_scheduler = ON;
2. Turn on the transaction timer
ALTER EVENT up_con_outTime_event ENABLE;
End closes the transaction timer (if necessary)
ALTER EVENT up_con_outTime_event DISABLE;
Another: attach an alternate sql statement
View stored procedures
show procedure status
View events
select * from mysql.event
Delete event
drop event test_aaa_event;
View event running status
select * from mysql.event
View stored procedure source code
SHOW CREATE PROCEDURE sel_consumelogs_tostatics;
View event creation source code
SHOW CREATE EVENT jfinal_consta_event