今天就跟大家聊聊有关MySQL故障切换中事件调度器的注意事项有哪些,可能很多人都不太了解,为了让大家更加了解,小编给大家总结了以下内容,希望大家根据这篇文章可以有所收获。
事件调度器(event)是在MySQL5.1中新增的任务调度器,解决了在之前版本中只能依赖系统定时任务才能完成的功能。
下边看一个案例:
开启event:
mysql> set global event_scheduler=ON;
Query OK, 0 rows affected (0.01 sec)
mysql> show variables like 'event%';
+-----------------+-------+
| Variable_name | Value |
+-----------------+-------+
| event_scheduler | ON |
+-----------------+-------+
在主从架构中,在master上创建一个event:
mysql> show create event testevent \G
*************************** 1. row ***************************
Event: testevent
sql_mode: STRICT_TRANS_TABLES,NO_ENGINE_SUBSTITUTION
time_zone: SYSTEM
Create Event: CREATE DEFINER=`root`@`%` EVENT `testevent` ON SCHEDULE EVERY 1 DAY STARTS '2017-09-11 23:50:00' ON COMPLETION NOT PRESERVE ENABLE DO create table test02 as select * from test01
character_set_client: utf8
collation_connection: utf8_general_ci
Database Collation: utf8_general_ci
1 row in set (0.00 sec)
使用slave进行同步,然后查看master和slave该event状态
master
mysql> show events \G
*************************** 1. row ***************************
Db: test
Name: testevent
Definer: root@%
Time zone: SYSTEM
Type: RECURRING
Execute at: NULL
Interval value: 1
Interval field: DAY
Starts: 2017-09-11 23:50:00
Ends: NULL
Status: ENABLED
Originator: 2
character_set_client: utf8
collation_connection: utf8_general_ci
Database Collation: utf8_general_ci
slave
mysql> show events \G
*************************** 1. row ***************************
Db: test
Name: testevent
Definer: root@%
Time zone: SYSTEM
Type: RECURRING
Execute at: NULL
Interval value: 1
Interval field: DAY
Starts: 2017-09-11 23:50:00
Ends: NULL
Status: SLAVESIDE_DISABLED
Originator: 2
character_set_client: utf8
collation_connection: utf8_general_ci
Database Collation: utf8_general_ci
也就是说event只能在master上触发,在slave上不能触发,如果slave上触发了,同步就坏掉了,当主从故障切换之后,slave就变成了master,需要人工开启事件状态:
alter event 'testevent' enable;
看完上述内容,你们对MySQL故障切换中事件调度器的注意事项有哪些有进一步的了解吗?如果还想了解更多知识或者相关内容,请关注亿速云行业资讯频道,感谢大家的支持。