这篇文章将为大家详细讲解有关MySQL 5.5如何创建和查看数据库计划任务,小编觉得挺实用的,因此分享给大家做个参考,希望大家阅读完这篇文章后可以有所收获。
–查看相关参数
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 5.5如何创建和查看数据库计划任务”这篇文章就分享到这里了,希望以上内容可以对大家有一定的帮助,使各位可以学到更多知识,如果觉得文章不错,请把它分享出去让更多的人看到。