MySQL故障切換之事件調度器(event)注意事項

來源:互聯網
上載者:User

在主從架構中,在master建立一個event,如下:

 
  1. mysql> show create event `insert`\G; 
  2. *************************** 1. row *************************** 
  3.                Event: insert 
  4.             sql_mode:  
  5.            time_zone: SYSTEM 
  6.         Create Event: CREATE DEFINER=`root`@`localhost` EVENT `insert` 
  7. ON SCHEDULE EVERY 1 MINUTE STARTS '2012-11-20 16:10:09' 
  8. ON COMPLETION PRESERVE ENABLE DO BEGIN 
  9. insert into t3(name) values('aa'); 
  10. END 
  11. character_set_client: utf8 
  12. collation_connection: utf8_general_ci 
  13.   Database Collation: utf8_general_ci 
  14. 1 row in set (0.02 sec) 
  15.  
  16. ERROR:  
  17. No query specified 

slave同步過去,結果是這樣的,注意紅色字型:

 
  1. mysql> show create event `insert`\G; 
  2. *************************** 1. row *************************** 
  3.                Event: insert 
  4.             sql_mode:  
  5.            time_zone: SYSTEM 
  6.         Create Event: CREATE DEFINER=`root`@`localhost` EVENT `insert` 
  7. ON SCHEDULE EVERY 1 MINUTE STARTS '2012-11-20 16:10:09' 
  8. ON COMPLETION PRESERVE DISABLE ON SLAVE DO BEGIN 
  9. insert into t3(name) values('aa'); 
  10. END 
  11. character_set_client: utf8 
  12. collation_connection: utf8_general_ci 
  13.   Database Collation: utf8_general_ci 
  14. 1 row in set (0.02 sec) 
  15.  
  16. ERROR:  
  17. No query specified 

再回過頭來,看下事件狀態,注意紅色字型:

在master上

 
  1. mysql> show events; 
  2. +------+--------+----------------+-----------+-----------+------------+----------------+----------------+---------------------+------+---------+------------+----------------------+----------------------+--------------------+ 
  3. | Db   | Name   | Definer        | Time zone | Type      | Execute at | Interval value | Interval field | Starts              | Ends | Status  | Originator | character_set_client | collation_connection | Database Collation | 
  4. +------+--------+----------------+-----------+-----------+------------+----------------+----------------+---------------------+------+---------+------------+----------------------+----------------------+--------------------+ 
  5. | test | insert | root@localhost | SYSTEM    | RECURRING | NULL       | 1              | MINUTE         | 2012-11-20 16:10:09 | NULL | ENABLED |         25 | utf8                 | utf8_general_ci      | utf8_general_ci    |  
  6. +------+--------+----------------+-----------+-----------+------------+----------------+----------------+---------------------+------+---------+------------+----------------------+----------------------+--------------------+ 
  7. 1 row in set (0.11 sec) 

在slave上

 
  1. mysql> show events; 
  2. +------+--------+----------------+-----------+-----------+------------+----------------+----------------+---------------------+------+--------------------+------------+----------------------+----------------------+--------------------+ 
  3. | Db   | Name   | Definer        | Time zone | Type      | Execute at | Interval value | Interval field | Starts              | Ends | Status             | Originator | character_set_client | collation_connection | Database Collation | 
  4. +------+--------+----------------+-----------+-----------+------------+----------------+----------------+---------------------+------+--------------------+------------+----------------------+----------------------+--------------------+ 
  5. | test | insert | root@localhost | SYSTEM    | RECURRING | NULL       | 1              | MINUTE         | 2012-11-20 16:10:09 | NULL | SLAVESIDE_DISABLED |         25 | utf8                 | utf8_general_ci      | utf8_general_ci    |  
  6. +------+--------+----------------+-----------+-----------+------------+----------------+----------------+---------------------+------+--------------------+------------+----------------------+----------------------+--------------------+ 
  7. 1 row in set (0.10 sec) 

也就是說,事件只能在master觸發,slave上不會觸發,否則如果slave上觸發了,同步複製就會壞掉。

當主從故障切換之後,VIP漂移到了以前的slave上,此時slave成了新的master。

但這時,事件的狀態還是維持SLAVESIDE_DISABLED,並不是也改成了ENABLED,這樣就會造成切換以後,事件無法執行。

所以,需要人工重新開啟事件狀態。

 
  1. mysql> alter event `insert` enable;  
  2. Query OK, 0 rows affected (0.05 sec) 


參考手冊:

650) this.width=650;" border="0" alt="" src="http://www.bkjia.com/uploads/allimg/131229/1Z42I4O-0.jpg" />

 

本文出自 “賀春暘的技術專欄” 部落格,請務必保留此出處http://hcymysql.blog.51cto.com/5223301/1067081

相關文章

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.