MySQL複製和效能最佳化

來源:互聯網
上載者:User

複製(Replication):通過複製執行過的語句或者資料集從主伺服器上複製到一個或多個從伺服器上實現多個資料庫伺服器之間資料庫的同步。

MySQL's built-in replication capability is the foundation for building large, highperformance applications on top of MySQL.

MySQL supports two kinds of replication: statement-based replication(基於語句的複製) and row-based replication(基於行的複製).

Statement-based (or "logical") replication has been available since MySQL 3.23, and it's what most people are using in production today

Row-based replication is new in MySQL 5.1.

Both kinds work by recording changes in the master's binary log and replaying the log on the slave

基於語句的複製:記錄改變資料庫的語句,將語句在從伺服器上在執行一遍,效率較高。

基於行的複製:將語句執行後的結果包括行的改變或者添加整個複製到從伺服器中去。

混合方式的複製:由MySQL自動來判斷。

複製過程:

主伺服器上線程:mysql dump

從伺服器兩個線程:I/O thread ,SQL thread。

過程:從伺服器的I/O 線程(主伺服器的遠程用戶端)不斷嘗試串連主伺服器,讀取其二進位日誌,主伺服器收到請求後將檢查自己的Binary Log並根據從伺服器發來的Relay Log的相關資訊來確認自從上次複製之後主伺服器內容是否有更新,如果有,則主伺服器啟動mysql dump線程,將對方所請求的資料返回給從伺服器,從伺服器收到資料後會將資料儲存在Relay Log。SQL thread 會不週期性讀取Relay Log,如果發現有更新,則讀取更新的語句或者行將其儲存在從伺服器上。

MySQL解決的問題:資料備份、負載平衡、高可用、資料分布(異地容災)、升級測試。

下面我們來實現基於MySQL主從複製的架構:

Master:192.168.1.11  MySQL已安裝完畢

[root@station39 ~]# vim /etc/my.cnf

log-bin=master-bin     //** update  line 50

log-bin-index=master-bin.index  //** add line 51

server-id       = 1           //** line 59

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 下一頁

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.