Master-slave replication One, How master-slave replication works MySQL the process of implementing 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) on the master side To implement MySQL replication you must first open the master side of the Binary log (that is, the binary log) otherwise it will not be implemented. The basic process of  MYSQL replication is as follows: (1) slave above IO Line subroutines the master and requests the location of the specified log file (or the log contents after the start of the log) (2) master receives an IO thread request from Slave, After specifying the location of the log based on this request information, the IO thread responsible for the replication returns this information to the IO thread of the slave (the returned confidence includes the binary file name of the master side and the location of the binary file, in addition to the information contained in the log) (3) after the slave IO thread receives the return information from the master side, the log contents are written to the Relay log file at the slave end, ( MYSQL-RELAY-BIN.XXX), and the Bin-log file and location records, to the master end are recorded in the Master-info file, So that the next time I can clearly tell master where I need to start from somewhere in the Bin-log, please send it to me. (4), slave SQL thread detection Relay log Center add content, immediately parse the contents of the master binary file, and execute the query statement inside . Second, the master-slave Environment master ip:10.0.0.201slave ip:10.0.0.202 (1) Operation operation file on Master is:/etc/ MY.CNF first open the Log-bin log and then set the Server-id to 1 to turn log-slave-updates off service mysqld restart Establish an internal replication communication user grant replication slave on *.* to ' admin ' @ ' 10.0.0.202 ' identified by ' 123456 ';flush privileges; (2) on slave operation operation file:/etc/ MY.CNF first Bin-log log is turned on Server-id set to 2 will log-slave-updates open the #pos number and the log file name on the master side >show master status\G; View service mysqld restart>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; When Master and slave hang up, slave loses part of the data: if you want to recover this lost data, the slave end has stopped the slave,change of the POS number and Bin-log to fill the current content of the slave end. To recover if the POS number and bin-log content of the master are filled in. (Cause: Check whether the logs with the master side are up-to-date based mainly on the POS number).