MySQL主備複製結構搭建

來源:互聯網
上載者:User

MySQL主備複製結構搭建

1 選擇兩個伺服器,分別作為主備資料庫

2 登陸到伺服器,

 yum install mysql ;

 yum install mysql-server;

3 啟動伺服器

service  mysqld start

4 分別root登陸mysql 執行如下命令,增加複製使用者並授權(主備都在192.168.119.*網段,為了方便主備切換,兩邊都建立)

GRANT  REPLICATION SLAVE,REPLICATION CLIENT on *.* to repl@'192.168.119.%' identified by '1234';


5 配置/etc/my.cnf

第一伺服器(主)

log_bin=mysql_bin
server_id=1


第二個伺服器(備)

log_bin=mysql_bin
server_id=2
read_only=1


6 登陸主(root)執行

show master status\G;


顯示

File: mysql-bin.000001
Position: 106

 

 

登陸備(root) 執行

測試 mysql -urepl -h192.168.119.128 -p1234 是否能串連到主庫,不能需要檢查防火牆或者/etc/my.cnf是否有訪問限制,修改配置

mysql -uroot登陸本地庫執行:

CHANGE MASTER TO
 MASTER_HOST='192.168.119.128',
 MASTER_USER='repl',
 MASTER_PASSWORD='1234',
 MASTER_LOG_FILE='mysql-bin.000001',
 MASTER_LOG_POS=106;


 start slave;

show slave status\G;

7,主庫上建立表,備庫上查看,可以看到

      備庫上repl建立表,顯示The MySQL server is running with the --read-only option so it cannot execute this statement

      因為配置了備庫為read_only

本文永久更新連結地址:

聯繫我們

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