MySQL 5.6主從複製及遇到的錯誤

來源:互聯網
上載者:User

MySQL的複製過程:每執行一個寫操作,它都會往自己的資料庫中存一份,與此同時這個寫操作也會儲存在二進位記錄檔中一份,並且把它們儲存為事件,所以在這個資料庫上,前端資料每執行一個寫操作或者有可能引起修改的操作,都會儲存一個事件,我們就把這個事件通過mysql伺服器3306連接埠發送給另外一台伺服器,另外一台伺服器把這個事件接收下來,接受下來以後先儲存在本地的記錄檔中,而後從這個記錄檔中一次讀一個事件並且在本地執行一下,然後儲存在資料庫裡面,這個過程就叫mysql的複製。

安裝mysql的過程就不講了,直接開始我們的主從複製的配置過程:

1、 開啟master和slave的二進位日誌功能,也就是在mysql的主設定檔/usr/local/mysql/etc/my.cnf中,添加log_bin=mysql-bin,將master的server_id 設定為1,slave的server_id=2.

下面是master的設定檔

[root@localhost ~]# cat /usr/local/mysql/etc/my.cnf | grep -v ^#| grep -v ^$
[mysqld]
 server_id = 1
 log_bin=mysql-bin
 log-bin-index = mysql-bin.index
 log-error = /var/log/mysql/mysql-error.log
 general_log = 1
 general_log_file = /var/log/mysql/mysql.log
 user = mysql
 basedir = /usr/local/mysql
 datadir = /datadir
 port = 3306
 socket = /var/lib/mysql/mysql5.sock
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES


接下來是slave的設定檔

[root@wordpress ~]# cat /usr/local/mysql/etc/my.cnf | grep -
v ^# | grep -v ^$
[mysqld]
 server_id = 2
 log_bin=mysql-bin
 log-bin-index = mysql-bin.index
 general_log = 1
 general_log_file = /var/log/mysql/mysql.log
 log-error=/var/log/mysql/mysql.error
 basedir = /usr/local/mysql
 datadir = /database
 port = 3306
 socket = /var/run/mysqld/mysql.sock
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES

推薦閱讀:

Ubuntu下Nginx做負載實現高效能WEB伺服器5---MySQL主主同步

生產環境MySQL主主同步主鍵衝突處理

MySQL主從失敗 錯誤Got fatal error 1236

MySQL主從複製,單台伺服器上實施

  • 1
  • 2
  • 3
  • 下一頁

相關文章

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.