MySQL master-slave relationship switching

Source: Internet
Author: User

Requirements such as the need to switch between the normal one and the primary from the main cascade from each other

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M02/71/4C/wKioL1XLAYnyTndVAAEbhAbwKyY248.jpg "title=" 20150812_2.png "alt=" Wkiol1xlaynytndvaaebhabwkyy248.jpg "/>

Here's the command for start slave until.


First, from left to right to do the conversion adjustment, a main two from the conversion to cascade from, first stop slave to the left is from the machine, we temporarily called S1 after, we need to operate on the right of the slave S2, it is best to use script execution, to ensure that does not affect online business, execute the statement as follows


Mysql-uroot-p "Password"-e "stop slave;"

Mysql-uroot-p "Password"-e "show Master Status\g" >/home/liuminkun/master.info

Mysql-uroot-p "Password"-e "show slave status\g" >/home/liuminkun/slave.info

Mysql-uroot-p "Password"-e "start slave;"



so we get in the text, the host m and a slave binlog and Pos letter, while confirmed that the Binlog file for M has a corresponding relationship to the Binlog file for S2


at this point we need to execute the start slave on the S1 of the cascade from which we need to convert until  master_log_file = ' Log_name ', master_log_pos = Log_pos; The Binlog name and Log_pos here use the slave status that you just got in the text .

Information, the SQL thread stops automatically when you run to the POS point of the Binlog file and the IO thread continues to run, as long as the change master to the master status information in the text just before start Slave View the synchronization status of the S1.


And vice versa, such operations can avoid the reconfiguration of the schema by re-doing MySQL, and can also solve the data consistency problem after switching.



This article from "Cloud Light Breeze Light" blog, declined reprint!

MySQL master-slave relationship switching

Related Article

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.