關於mysql主從複製原理的官方文檔解釋

MySQL複製功能是通過三個線程實現的,一個在主服務器上,兩個在從服務器上:
  • Binlog dump thread: 在slave連接master時,master創建了一個線程, 將二進制日誌內容發送給slave。 這個線程可以在master上使用show processlist查看到,是一個標識爲該Binlog Dump線程。
  • Slave I/O thread: 當執行start slave在slave服務器上時,slave服務器創建一個I / O線程,該線程連接到master服務器並要求master服務器發送記錄在其二進制日誌中的更新。
    從屬I / O線程讀取master 服務器Binlog Dump線程發送的更新,並將其複製到slave服務器中繼日誌relay-log的文件中。
    同樣也可以通過 show processlist命令查看,該線程的狀態顯示爲 Slave_IO_running
  • Slave SQL thread: slave服務器創建一個SQL線程以讀取中繼日誌(relay-log)中的事件並執行。
master的Binlog dump thread查看
mysql> SHOW PROCESSLIST\G
*************************** 1. row ***************************
     Id: 2
   User: root
   Host: localhost:32931
     db: NULL
Command: Binlog Dump
   Time: 94
  State: Has sent all binlog to slave; waiting for binlog to
         be updated
   Info: NULL
slave的Slave I/O thread和Slave SQL thread查看
mysql> SHOW PROCESSLIST\G
*************************** 1. row ***************************
     Id: 10
   User: system user
   Host:
     db: NULL
Command: Connect
   Time: 11
  State: Waiting for master to send event
   Info: NULL
*************************** 2. row ***************************
     Id: 11
   User: system user
   Host:
     db: NULL
Command: Connect
   Time: 11
  State: Has read all relay log; waiting for the slave I/O
         thread to update it
   Info: NULL
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章