mysql主從複製

來源:互聯網
上載者:User

標籤:mysql 主從複製

主從複製步驟


1:開啟主庫binlog功能

   查看3306  是否開啟

   grep  log-bin /etc/my.cnf

   查看是否不一樣

2:確保server-id 不同

   grep server-id /etc/my.cnf

   grep server-id /data/3307/my.cnf

3:主庫授權 複製的使用者rep

  grant replication slave on *.* to [email protected]‘192.168.1.102‘ identified by ‘2017‘;

  

  查看是否授權成功

4:鎖表,查看binlog 位置點

   先鎖表 保證資料庫一致

   flush table with read lock;

   

   show  master status; 看看備份點

   

     show  master status;

+------------------+----------+--------------+------------------+

| File             | Position | Binlog_Do_DB | Binlog_Ignore_DB |

+------------------+----------+--------------+------------------+

| mysql-bin.000053 |      339 |              |                  |

+------------------+----------+--------------+------------------+

5.新開視窗匯出全備

  mysqldump -uroot -p2017 -A -B --events -S /tmp/mysql.sock|gzip >/home/chaofu/rep_bak_$(date +%F).sql.gz


6: unlock table 解除鎖表


從庫:

1:確保server-id 不同

2:把主庫的資料恢複到 從 庫

   gzip -d  rep_bak.sql.gz

   mysql -uroot -p -S /data/3307/mysql.sock < /home/chaofu/rep_bak_2017-11-21.sql

3:找位置點,配置master.info

CHANGE MASTER TO

MASTER_HOST=‘192.168.1.102‘, 

MASTER_PORT=3306,

MASTER_USER=‘rep‘,

MASTER_PASSWORD=‘2017‘,

MASTER_LOG_FILE=‘mysql-bin.000053‘,

MASTER_LOG_POS=339;

  

  

  find /data/3307/data -type -f -name "*.info"


4: 開啟 備份開關

 start slave;

 show slave status \G;

 從庫兩個線程

 5:測試


主從複製原理圖


本文出自 “9124122” 部落格,請務必保留此出處http://9134122.blog.51cto.com/9124122/1983955

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.