--查看相关参数
mysql> show variables like '%event%';
+---------------------------------------------------+-------+
| Variable_name | Value |
+---------------------------------------------------+-------+
| event_scheduler | OFF |
| performance_schema_events_waits_history_long_size | 10000 |
| performance_schema_events_waits_history_size | 10 |
+---------------------------------------------------+-------+
3 rows in set (0.00 sec)
--开启相关参数
mysql> set global event_scheduler = 1;
Query OK, 0 rows affected (0.00 sec)
mysql> show variables like '%event%';
+---------------------------------------------------+-------+
| Variable_name | Value |
+---------------------------------------------------+-------+
| event_scheduler | ON |
| performance_schema_events_waits_history_long_size | 10000 |
| performance_schema_events_waits_history_size | 10 |
+---------------------------------------------------+-------+
3 rows in set (0.00 sec)
--开启参数后,在线程中会出现event_scheduler相关线程
mysql> show processlist\G
*************************** 7. row ***************************
Id: 13
User: event_scheduler
Host: localhost
db: NULL
Command: Daemon
Time: 474
State: Waiting for next activation
Info: NULL
7 rows in set (0.00 sec)
--创建计划任务
mysql> CREATE EVENT myevent
-> ON SCHEDULE AT CURRENT_TIMESTAMP + INTERVAL 1 HOUR
-> DO
-> UPDATE fire.t12 SET sal = sal + 100;
Query OK, 0 rows affected (0.02 sec)
--查看数据库里面的计划任务
mysql> show events from fire\G
*************************** 1. row ***************************
Db: fire
Name: myevent
Definer: system@localhost
Time zone: SYSTEM
Type: ONE TIME
Execute at: 2016-05-23 02:48:03
Interval value: NULL
Interval field: NULL
Starts: NULL
Ends: NULL
Status: ENABLED
Originator: 100
character_set_client: gbk
collation_connection: gbk_chinese_ci
Database Collation: utf8_general_ci
1 row in set (0.00 sec)
--查看计划任务的内容
mysql> show create event myevent\G
*************************** 1. row ***************************
Event: myevent
sql_mode: STRICT_TRANS_TABLES,NO_ENGINE_SUBSTITUTION
time_zone: SYSTEM
Create Event: CREATE DEFINER=`system`@`localhost` EVENT `myevent` ON SCHEDULE AT '2016-05-23 02:48:03' ON COMPLETION NOT PRESERVE ENABLE DO UPDATE fire.t12 SET sal = sal + 100
character_set_client: gbk
collation_connection: gbk_chinese_ci
Database Collation: utf8_general_ci
1 row in set (0.00 sec)
--禁止计划任务
mysql> ALTER EVENT myevent DISABLE;
mysql> show variables like '%event%';
+---------------------------------------------------+-------+
| Variable_name | Value |
+---------------------------------------------------+-------+
| event_scheduler | OFF |
| performance_schema_events_waits_history_long_size | 10000 |
| performance_schema_events_waits_history_size | 10 |
+---------------------------------------------------+-------+
3 rows in set (0.00 sec)
--开启相关参数
mysql> set global event_scheduler = 1;
Query OK, 0 rows affected (0.00 sec)
mysql> show variables like '%event%';
+---------------------------------------------------+-------+
| Variable_name | Value |
+---------------------------------------------------+-------+
| event_scheduler | ON |
| performance_schema_events_waits_history_long_size | 10000 |
| performance_schema_events_waits_history_size | 10 |
+---------------------------------------------------+-------+
3 rows in set (0.00 sec)
--开启参数后,在线程中会出现event_scheduler相关线程
mysql> show processlist\G
*************************** 7. row ***************************
Id: 13
User: event_scheduler
Host: localhost
db: NULL
Command: Daemon
Time: 474
State: Waiting for next activation
Info: NULL
7 rows in set (0.00 sec)
--创建计划任务
mysql> CREATE EVENT myevent
-> ON SCHEDULE AT CURRENT_TIMESTAMP + INTERVAL 1 HOUR
-> DO
-> UPDATE fire.t12 SET sal = sal + 100;
Query OK, 0 rows affected (0.02 sec)
--查看数据库里面的计划任务
mysql> show events from fire\G
*************************** 1. row ***************************
Db: fire
Name: myevent
Definer: system@localhost
Time zone: SYSTEM
Type: ONE TIME
Execute at: 2016-05-23 02:48:03
Interval value: NULL
Interval field: NULL
Starts: NULL
Ends: NULL
Status: ENABLED
Originator: 100
character_set_client: gbk
collation_connection: gbk_chinese_ci
Database Collation: utf8_general_ci
1 row in set (0.00 sec)
--查看计划任务的内容
mysql> show create event myevent\G
*************************** 1. row ***************************
Event: myevent
sql_mode: STRICT_TRANS_TABLES,NO_ENGINE_SUBSTITUTION
time_zone: SYSTEM
Create Event: CREATE DEFINER=`system`@`localhost` EVENT `myevent` ON SCHEDULE AT '2016-05-23 02:48:03' ON COMPLETION NOT PRESERVE ENABLE DO UPDATE fire.t12 SET sal = sal + 100
character_set_client: gbk
collation_connection: gbk_chinese_ci
Database Collation: utf8_general_ci
1 row in set (0.00 sec)
--禁止计划任务
mysql> ALTER EVENT myevent DISABLE;
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/26506993/viewspace-2105493/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/26506993/viewspace-2105493/