1. Pre-conditions, you need to set the server and MySQL time to the East Eight, php.ini and MY.CNF configuration (refer to the previous article)
2, go to MySQL client, recommended navicat for MySQL
3, first check whether the function of the timer is turned on:
# # # #调试MYSQL定时器--The time setting is correctly executed below does not affect xzz1128 #####set time_zone = 'event_scheduler '; # #查看是否开启了event定时器功能 GLOBAL event_scheduler = 1;//Open Select Now ();
4, remind: Although here with set global Event_scheduler = ON statement to turn on the event, but each restart the computer. Or restart the MySQL service , you will find that the event automatically shuts down (Event_scheduler=off), so you want to keep the event open, it is best to modify the configuration file, so that the MySQL service startup time, only need to the [mysqld] section of the MY.CNF configuration file is added Event_scheduler=on , as follows:
5, First, the new user table:
--------------------------------table structure for ' user '------------------------------DROP table IF EXISTS ' user '; CREATE TABLE ' user ' ( ' id ' bigint) NOT null auto_increment, ' name ' varchar ($) NOT NULL, ' address ' varcha R (+) not NULL, ' Addtime ' datetime is NOT NULL, PRIMARY KEY (' id ')) engine=innodb DEFAULT Charset=utf8;
Then, a new event, there are two types of events, one is the interval trigger and the other is a specific event trigger.
6. The following code describes the timer to carry out the continuous action (each time points need to dry) and one -off action (only once, run out of the dump)
################# mysql persistent timer -xzz 1128 ##########################DROP EVENTIFEXISTS ' Event_minute ';D elimiter;; CREATE Definer= ' root ' @ ' localhost ' EVENT ' event_minute ' on SCHEDULE every 1 minute starts ' 2017-11-28 15:26:00 'On completion PRESERVE#When this event doesn't happen again, it won't be dropped.ENABLE DoBEGIN INSERT into ' user ' (name, address,addtime) VALUES (' test1 ', ' test1 ',Now ()); INSERT into ' user ' (name, address,addtime) VALUES (' test2 ', ' test2 ',Now ());END;;D Elimiter;################# #mysql Disposable timer #################################DROP EVENTIFEXISTS ' event_at ';D elimiter;; CREATE Definer= ' root ' @ ' localhost ' EVENT ' event_at ' on SCHEDULE at ' 2017-11-28 15:39:00 'On completion not PRESERVE#When this event doesn't happen again, it's going to drop off.ENABLE DoBEGIN INSERT into ' user ' (name, address,addtime) VALUES (' at ', ' at ',Now ());END;;D Elimiter;
7. Other more important Operation statements
# # #关闭 \ Open Timer ALTER EVENT Event_minute DISABLE; ALTER EVENT Event_minute ENABLE; # # #查询定时器状态 MySQL. event;
8, look at the effect:
8. Thanks:
@Author the same yard as the wind.
@HomePageUrl http://www.cnblogs.com/chenpi/
"MySQL" Topsy timer