Mysql replication from the master is how to achieve

mysql replication from the master is how to achieve
Foreword

MySQL master is copied from MySQL itself comes with a feature that does not require additional third-party software can be achieved, it is not a copy function to copy files to achieve, but with the master binlog log file inside the SQL commands implemented from copy, and then I can be understood as a master-side implementation of SQL commands, it will perform again at the same Salve end, so as to achieve master-slave replication.

MySQL master-slave replication architecture diagram

一主一从

master-slave-replication-01master-slave-replication-01

一主多从

master-slave-replication-02master-slave-replication-02

级联

master-slave-replication-03master-slave-replication-03

双主一从

master-slave-replication-04master-slave-replication-04

互为主从

master-slave-replication-05master-slave-replication-05

环状

master-slave-replication-06master-slave-replication-06

Copy the master-slave principle

MySQL is replication master from an asynchronous replication process, a database replication from Slave to Master database, implemented between the Master and the Slave whole process from the master copy is done by the three threads participating in which there are two threads (SQL IO thread and thread) in the Slave side, another thread (IO thread) at the Master side.

From the main flowchart replication

Flow Description:

MySQL master-slave replication before we need to start the Master database and then start Salve database, and then execute start slave database in Salve ;, after the execution is completed, the flow is as follows: the

Salve的IO线程会读取mastr.info文件中配置好的主库信息,比如说存放的有:Master数据库的用户名、密码、端口、还有Master的binlog索引位置;
拿到信息之后就带着信息去链接Master的主库IO线程
当主库的IO线程先检查SLave传过来的配置信息是否正确,如果正确,就拿着Slave传过来的binlog索引位置和Master库的binlog文件中最后一个索引位置进行对比,如果一致就陷入等待状态,等待Master的binlog索引位置更新;
如果不一致就把Slave传过来的binlog索引位置往后的所有SQL语句包括最后一条SQL语句的索引位置发送个给Slave的IO线程;
Slave的IO线程拿到信息之后,先把Master传过来的binlog索引在Slave的master.info文件中进行更新;
然后再把Master传过来的SQL语句写入到relay文件中,然后继续循环执行第二个步骤;
Slave的SQL线程会一直持续的观察relay日志文件中是否有改动,如果没有就继续监听;
如果发现relay中有变动,那么就获取变动的内容转换为SQL语句,并且把SQL语句在Salve的数据库中进行执行

Guess you like

Origin www.cnblogs.com/djwhome/p/12536275.html