mysql主主(基於bin-log)

來源:互聯網
上載者:User

標籤:mysql   主主   bin-log   io   sql   

準備兩台機器,分別安裝好mysql5.6.29:

192.168.220.143 (server1)

192.168.220.144 (server2)


mysql主主

啟動雙主要資料庫,建立同步處理的使用者

server1:

grant replication slave on *.* to ‘server‘@‘192.168.220.144‘ identified by ‘123456‘;

flush privileges;


server2:

grant replication slave on *.* to ‘server‘@‘192.168.220.143‘ identified by ‘123456‘;

flush privileges;


my.cnf配置

server1:

[mysqld1]
basedir = /usr/local/mysql
datadir = /data/mysql
port = 3306
socket = /tmp/mysql.sock
log-bin=mysql-bin
server-id=10
auto-increment-increment = 2
auto-increment-offset = 1
log-slave-updates
slave-skip-errors=all
sync_binlog=1
innodb_data_file_path=ibdata1:76M;ibdata2:12m:autoextend


server2:

basedir = /usr/local/mysql
datadir = /data/mysql
port = 3306
log-bin=mysql-bin
server-id=20
auto-increment-increment = 2
auto-increment-offset = 2
log-slave-updates
slave-skip-errors=all
sync_binlog=1

innodb_data_file_path=ibdata1:76M;ibdata2:12m:autoextend


記錄bin-log和pos位置,server1和server2分別記錄

server1:

show master status;

mysql> show master status;
+------------------+----------+--------------+------------------+-------------------+
| File             | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+------------------+----------+--------------+------------------+-------------------+
| mysql-bin.000002 |     423  |              |                  |                   |
+------------------+----------+--------------+------------------+-------------------+


server2:

show master status;

mysql> show master status;
+------------------+----------+--------------+------------------+-------------------+
| File             | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+------------------+----------+--------------+------------------+-------------------+
| mysql-bin.000002 |     423  |              |                  |                   |
+------------------+----------+--------------+------------------+-------------------+


啟動複製

server1:

stop slave;

change master to master_host=‘192.168.220.144‘,master_user=‘server‘,master_password=‘123456‘,master_log_file=‘mysql-bin.000002‘,master_log_pos=423;

start slave;


server2:

stop slave;

change master to master_host=‘192.168.220.143‘,master_user=‘server‘,master_password=‘123456‘,master_log_file=‘mysql-bin.000002‘,master_log_pos=423;

start slave;


show slave status\G;

確保狀態:
Slave_IO_Running: Yes
Slave_SQL_Running: Yes


參數說明
auto-increment-increment= 2 # 應設為整個結構中伺服器的總數
auto-increment-offset = 1 # 設定資料庫中自動成長的起點,避免兩台伺服器資料同步時出現主鍵衝突
log-slave-updates # 這個參數用來配置從伺服器的更新是否寫入二進位日誌,這個選項預設是不開啟的,但是,如果這個從伺服器B是伺服器A的從伺服器,同時還作為伺服器C的主伺服器,那麼就需要開發這個選項,這樣它的從伺服器C才能獲得它的二進位日誌進行同步操作
slave-skip-errors # 在複製過程中,由於各種的原因,從伺服器可能會遇到執行BINLOG中的SQL出錯的情況,在預設情況下,伺服器會停止複製進程,不再進行同步,等到使用者自行來處理。Slave-skip-errors就是用來定義複製過程中從伺服器可以自動跳過的錯誤號碼,當複製過程中遇到定義的錯誤號碼,就可以自動跳過,直接執行後面的SQL語句。--slave-skip-errors=[err1,err2,…….ALL]

但必須注意的是,啟動這個參數,如果處理不當,很可能造成主從資料庫的資料不同步,在應用中需要根據實際情況,如果對資料完整性要求不是很嚴格,那麼這個選項確實可以減輕維護的成本。

sync_binlog=0,當事務提交之後,MySQL不做fsync之類的磁碟同步指令重新整理binlog_cache中的資訊到磁碟,而讓Filesystem自行決定什麼時候來做同步,或者cache滿了之後才同步到磁碟。
sync_binlog=n,當每進行n次事務提交之後,MySQL將進行一次fsync之類的磁碟同步指令來將binlog_cache中的資料強制寫入磁碟。


mysql主主(基於bin-log)

聯繫我們

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