Considerations for MySQL failover event

Source: Internet
Author: User

In the master-slave architecture, create an event on the master, as shown below:

 
 
  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 

When slave is synced, the result is as follows. Pay attention to the red font:

 
 
  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 

Let's look back at the event status and pay attention to the red font:

On the 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) 

On 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) 

That is to say, the event can only be triggered on the master node, but not on the slave node. Otherwise, if the slave node is triggered, synchronization replication will break down.

After the master-slave failover, the VIP will drift to the previous slave, and the slave will become a new master.

However, the event status is still "SLAVESIDE_DISABLED", not changed to "ENABLED". In this way, the event cannot be executed after the switch.

Therefore, you need to manually re-enable the event status.

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


Reference manual:

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

 

This article is from the "hechun's technical column" blog, please be sure to keep this source http://hcymysql.blog.51cto.com/5223301/1067081

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.