mysql GTID主從復(fù)制詳細(xì)說明
發(fā)表時(shí)間:2023-07-27 來源:明輝站整理相關(guān)軟件相關(guān)文章人氣:
[摘要]MySQL復(fù)制在業(yè)界里有叫:mysql同步,ab復(fù)制等。專業(yè)名稱就是叫:復(fù)制復(fù)制是單向的,只能從master復(fù)制到slave上,延時(shí)基本上是毫秒級(jí)別的。一組復(fù)制結(jié)構(gòu)中可以有多個(gè)slave,對(duì)于mas...
MySQL復(fù)制在業(yè)界里有叫:mysql同步,ab復(fù)制等。專業(yè)名稱就是叫:復(fù)制
復(fù)制是單向的,只能從master復(fù)制到slave上,延時(shí)基本上是毫秒級(jí)別的。
一組復(fù)制結(jié)構(gòu)中可以有多個(gè)slave,對(duì)于master一般場(chǎng)景推薦只有一個(gè)。
master用戶寫入數(shù)據(jù),生成event記到binary log中
slave接收master上傳來的binlog,然后按順序應(yīng)用,重現(xiàn)master上的用戶操作。
記錄最小的單位是一個(gè)event,日志前4個(gè)字節(jié)是一個(gè)magic number,接下來19個(gè)字節(jié)記錄formatt desc event:FDE
MySQL5.6增加了GTID復(fù)制
要求:
1、 主庫上線,主庫不停止服務(wù)的前提下做主從復(fù)制
2、 新添加一個(gè)叢庫
操作:
1、 在主庫導(dǎo)出數(shù)據(jù)(主庫正常運(yùn)行);

2、 將主庫的sql文件傳到叢庫;

3、 叢庫恢復(fù)數(shù)據(jù)庫;

4、 在主服務(wù)器上,創(chuàng)建復(fù)制賬號(hào),賦權(quán)限
Mysql > GRANT REPLICATION SLAVE ON *.* TO 'repluser'@'3.9.8.%' IDENTIFIED BY 'replpass';
Mysql > flush privileges;
5、 配置從服務(wù)器的防火墻,允許防火墻通過3306端口
# vim /etc/sysconfig/iptables
添加
-A INPUT -m state –state NEW -m tcp -p tcp –dport 3306 -j ACCEPT(允許3306端口通過防火墻)
重啟防火墻服務(wù),使其生效
#service iptables restart
6、 叢庫修改配置文件
# vim /etc/my.cnf
添加

7、 在從服務(wù)器上使用主mysql上創(chuàng)建的賬號(hào)密碼登錄并進(jìn)行復(fù)制
mysql> change master to master_host='3.9.8.13', master_user='repluser',master_password='replpass',master_auto_position=1;

8、 叢庫啟動(dòng)主從復(fù)制(可能會(huì)報(bào)錯(cuò),參考10.問題集1) )
mysql> start slave;
9、 檢測(cè)主從復(fù)制
mysql> show slave status\G
10、 問題集
1) 啟動(dòng)主從復(fù)制,報(bào)錯(cuò)1872:slave failed to initialize relay log info structure from the repository.

mysql> reset slave;
mysql> change master to master_host='3.9.8.13', master_user='repluser',master_password='replpass',master_auto_position=1;
mysql> start slave;

以上就是mysql GTID主從復(fù)制詳解的詳細(xì)內(nèi)容,更多請(qǐng)關(guān)注php中文網(wǎng)其它相關(guān)文章!
學(xué)習(xí)教程快速掌握從入門到精通的SQL知識(shí)。