MySQL Master-slave replication

Source: Internet
Author: User


First, master-slave replication works
The process by which MySQL implements the entire replication between master and slave is done by 3 threads, of which two threads (SQL thread and IO thread) are on the slave side, and another thread (IO thread) on the master side
Note: To achieve MySQL replication you must first open the binary log (that is, the binary log) on the master side, otherwise you will not be able to implement
The basic process for MySQL replication is as follows:
(1) Slave The above IO thread initiates the connection and requests the location of the specified log file
(2) master receives a request from the Slaveio thread and returns this information to Slave's IO thread (return information) by specifying the location of the log based on the requested information, using the IO thread responsible for the replication (i.e. the Masterio thread).
(3) After the slave IO thread receives the return information from the master side, the log contents are written to the slave side relay Log file (mysql-relay-bin.xxx), and read the Bin-log file and location on the master side, recorded in the Master=info file, so that the next time you can clearly tell master from where to start transmitting bin-log content
(4) Slave SQL thread detection: Relay log Add content, immediately parse the contents of the master binary file, and execute the inside of the query statement


Second, the specific operation

(1) operation on master first the Bin-log log is opened and then Server-id set to 1 will log-slave-updates to shut down establish an internal replication communication user grant replication Slave on *. * to ' Admin ' @ ' 10.0.0.202 ' identified by ' 123456 '; flush privileges; (2) Operation on slave first Bin-log log is turned on next Server-id set to 2 will log-slave-updates open >stop Slave;>change master to  master_host= ' 10.0.0.201 ', master_user= ' admin ', master_password= ' 123456 ', master_log_file= ' mysql-bin.000005 ', master_log_pos=578 ; >start slave;>show slave status\g;



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.