MySQL複製原理

來源:互聯網
上載者:User

標籤:log   安全   strong   mysql複製   replicat   發送   速度   http   syn   

參考官網:https://dev.mysql.com/doc/refman/5.7/en/replication-implementation-details.html

MySQL複製功能是通過三個線程實現的,包括主上的binlog dump tread和從上的sql thread、I/O ttread

Binlog dump thread

master建立binlog dump thread,用於 當slave串連到master時發送binlog events給其,dump thread每次讀取將要發送給slave的每個event時

先獲得lock在binary log,讀完之後再 釋放。

Slave I/O thread

當執行 START SLAVE 在slave端執行後,slave會建立I/O thread  串連到master主動讀取dump thread將最新的binlog events寫到本地的relay log中

Slave SQL thread

slave建立SQL thread從relay log中讀取event並應用

 

I/O thread讀取event的速度並不因為server執行的慢而變慢,即使slave的I/O thread 停止一會,當再次開啟的時候也能迅速的擷取master中所有

最新的binlog內容到relay log,即使SQL thread有很大的延遲。如果slave在SQL thread運用完所有的relay log之前停止了,I/O thread至少擷取到

了到目前為止在master上所發生的所有交易記錄到relay  log,保證安全複製,到slave 下次啟動時接著應用。

如果maser  通過show processlist看不到binlog dump thread,則說明複製已經停了。

MySQL複製原理

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.