7.1 請簡述復(fù)制的原理和流程
MySQL的復(fù)制原理:Master上面事務(wù)提交時會將該事務(wù)的binlog event寫入binlogfile,然后master將binlogevent傳到slave上面,slave應(yīng)用該binlog event實現(xiàn)邏輯復(fù)制。
Mysql 的復(fù)制流程:
MySQL的復(fù)制是基于如下3個線程的交互(多線程復(fù)制里面應(yīng)該是4類線程):
a. Master上面的binlogdump線程,該線程負責將master的binlogevent傳到slave;
b. Slave上面的IO線程,該線程負責接收Master傳過來的binlog,并寫入relay log;
c. Slave上面的SQL線程,該線程負責讀取relay log并執(zhí)行;
d. 如果是多線程復(fù)制,無論是5.6庫級別的假多線程還是MariaDB或者5.7的真正的多線程復(fù)制,SQL線程只做coordinator,只負責把relay log中的binlog讀出來然后交給worker線程,woker線程負責具體binlog event的執(zhí)行;
7.2 如何確保復(fù)制的一致性
7.2 Seconds_Behind_Master值的含義
Doc里邊是這樣說的:
This field isan indication of how “l(fā)ate” the slave is:? When the slave is actively PRocessing updates,this field shows the difference between the current timestamp on the slave andthe original timestamp logged on the master for the most event currently beingprocessed on the slave.? When no event is currently being processed onthe slave, this value is 0.
意思是說
1)當slave正在處理更新,該字段表示當前slave的時間戳與最近在slave上執(zhí)行的事件(master上記錄的,也就是slave上relay-log中的事件)的時間戳的差值。2)當slave沒有事件處理(relay-log),顯示的值為0。
7.3 口述復(fù)制的搭建步驟?
1> .主庫授權(quán):grant replication slave on *.* to 'xx'@'xxx' identified by 'xx';
2>.配置N的my.cnf:
修改server_id
3>mysqldump -uxx -pxx -AER --single-transaction --master-data > mas.sql
4>.slave導(dǎo)入mas.sql,如果沒有master-data,則需要手動change master
5>.開啟start slave;
6>.檢查同步狀態(tài)show slave status;
7.4如何校驗復(fù)制的一致性新聞熱點
疑難解答