MYSQL主備複製結構搭建,mysql主結構搭建

來源:互聯網
上載者:User

MYSQL主備複製結構搭建,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









著作權聲明:本文為博主原創文章,未經博主允許不得轉載。

相關文章

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.