Mysql计划任务
1、检查计划任务是否开启
mysql> set global event_scheduler=off;
Query OK, 0 rows affected
mysql> select @@event_scheduler;
+-------------------+
| @@event_scheduler |
+-------------------+
| OFF |
+-------------------+
1 row in set
mysql> set global event_scheduler=on;
Query OK, 0 rows affected
mysql> select @@event_scheduler;
+-------------------+
| @@event_scheduler |
+-------------------+
| ON |
+-------------------+
1 row in set
2、创建计划任务
mysql> show events;
Empty set
mysql> create event event_insert on schedule every 1 second enable do insert into stu (name,age,updatetime) values('Caroline',5,now());
Query OK, 0 rows affected
mysql> show events;
+--------+--------------+---------+-----------+-----------+------------+----------------+----------------+---------------------+------+---------+------------+----------------------+----------------------+--------------------+
| Db | Name | Definer | Time zone | Type | Execute at | Interval value | Interval field | Starts | Ends | Status | Originator | character_set_client | collation_connection | Database Collation |
+--------+--------------+---------+-----------+-----------+------------+----------------+----------------+---------------------+------+---------+------------+----------------------+----------------------+--------------------+
| testdb | event_insert | root@% | SYSTEM | RECURRING | NULL | 1 | SECOND | 2015-03-25 19:57:41 | NULL | ENABLED | 0 | utf8 | utf8_general_ci | utf8_general_ci |
+--------+--------------+---------+-----------+-----------+------------+----------------+----------------+---------------------+------+---------+------------+----------------------+----------------------+--------------------+
1 row in set
3、定时添加记录
mysql> delete from stu;
Query OK, 6 rows affected
mysql> select * from stu;
+-----+----------+-----+---------------------+
| Id | Name | Age | updatetime |
+-----+----------+-----+---------------------+
| 232 | Caroline | 5 | 2015-03-25 19:58:57 |
| 233 | Caroline | 5 | 2015-03-25 19:58:58 |
+-----+----------+-----+---------------------+
2 rows in set
4、修改计划任务
mysql> alter event event_insert on schedule every 1 second disable;
Query OK, 0 rows affected