MySQL Master-slave failover

Source: Internet
Author: User

A: Environmental 192.168.1.100 master192.168.1.101 slave1192.168.1.102 slave2 slave1,slave2 are connected to the master.   II: Simulate master failure Close Master Instance service mysql stop at this point, show slave status\g on Slave1,slave2 will find an error: Last_ Io_error: error reconnecting to master ' [email protected]:3307 '  - retry-time :  60 retries: 1 io process and SQL process State: slave_io_running: connecting (This state indicates that it will always try to re-connect the master, if the master is OK, The process status will automatically turn to Yes) Slave_sql_running: yes at this point, master cannot provide read-write services. We want to promote the latest slave in the main. Three: Switch step 3.1 Make sure that all relay log are fully read and executed:stopslave io_thread;showprocesslist; from the library until you see slave has  Read all relay log; waitingfor more updates, it means that the update has been performed from the library or through Show slave  status View Slave_sql_running_state: slave has read allrelay log; waiting  for more updates 3.2  Choose a new Main library compare to select Relay_master_log_file,exec_master_log_pos largest as the new main library, Here we choose SLAVE1 as the new main Library in fact, if the two from the IO process has been normal, no lag behind the Lord, and Relay log have been heavyLet's do it, two from the same, whichever you choose. Here choose Slave1 as the new master.  3.3  Configure the login slave1, execute stop slave; and enter the database directory, Delete the Master.info and Relay-log.info files (you can back up the files before deleting them), configure the My.cnf file, turn on Log-bin, and if you have Log-slaves-updates=1 and Read-only=1, comment them out. Then restart Slave1. 3.4 reset master on slave1 reset master, the binary log is regenerated. mysql> reset master; query ok, 0 rows affected  (0.02 sec)  mysql> show binary  logs;+------------------+-----------+| log_name         |  file_size |+------------------+-----------+| mysql-bin.000001 |        154 |+------------------+-----------+1 row in set  (0.00 sec)  3.5 Create a user for synchronization if slave1 fully synchronizes master, this step can be omitted.  3.6 slave2 Point to Slave1[sql] view plain copymysql> change master to  master_user= ' Repuser ', master_password= ' Beijing ', master_host= ' 192.168.1.101 ', Master_port=3307,masTer_log_file= ' mysql-bin.000001 ', master_log_pos=154;  query ok, 0 rows affected,  2 warnings  (0.00 sec)     mysql> start slave;   query ok, 0 rows affected  (0.00 sec)    3.7  The program write IP to slave1 IP program before the record is the master IP, now master down, it is necessary to change the IP.


This article is from the "Linux operation and Maintenance" blog, reproduced please contact the author!

MySQL Master-slave failover

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.