mysql主從複製

來源:互聯網
上載者:User

標籤:style   blog   color   io   os   ar   for   strong   資料   

     外網資料庫為主,內網資料庫為從。首先確保主要資料庫所在的伺服器防火牆開啟。

     如果資料庫在做主從的時候已經有資料了, 則需要進行鎖表操作.

              mysql> flush tables with read lock;

     記住資料導完後要解鎖:

            mysql> unloclk tables;

     一.配置主要資料庫master 

     1.配置master主要資料庫

[mysqld]server-id       = 1 //分配server-idlog-bin         = master-bin //預設mysql-bin,可以不修改

    2.在master建立同步帳號:

  grant replication client,replication slave on *.* to [email protected]‘218.108.90.94‘ identified by ‘repl‘ ;

    3.查看binlog日誌:

show master status;

     查看A的狀態,記錄下file的位置和postion的參數

二 .配置slave從資料庫

   1.配置從資料庫

server-id=208log-bin=mysql-bin   //建議log-bin功能也開啟binlog-format=mixedrelay-log=mysql-relay

 

2. 指向主要資料庫

先關閉slave  stop slave;

CHANGE MASTER TO MASTER_HOST=‘server A ip‘,MASTER_PORT=3306,MASTER_USER=‘user‘,MASTER_PASSWORD=‘password‘,MASTER_LOG_FILE=‘mysql-bin.000001‘,MASTER_LOG_POS=0;

開啟slave :start slave;

查看slave狀態:show slave status;

 

ps: 如果要刪除slave資訊可以

change master to master_host = ‘‘;然後 reset slave;

 

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.