標籤:mysql 主從 設定
MYSQL一主多從配置
主伺服器:192.168.26.210
從伺服器:192.168.26.211
從伺服器:192.168.26.212
作業系統:centos6.6
安裝MYSQL:略(採用5.1.73版本)
設定設定檔:192.168.26.210(主)
650) this.width=650;" width="570" height="423" src="/e/u261/themes/default/images/spacer.gif" style="background:url("/e/u261/lang/zh-cn/images/localimage.png") no-repeat center;border:1px solid #ddd;" alt="spacer.gif" />
從伺服器設定檔:192.168.26.211(從1)
650) this.width=650;" width="560" height="428" src="/e/u261/themes/default/images/spacer.gif" style="background:url("/e/u261/lang/zh-cn/images/localimage.png") no-repeat center;border:1px solid #ddd;" alt="spacer.gif" />
從伺服器設定檔:192.168.26.212(從2)
650) this.width=650;" width="519" height="375" src="/e/u261/themes/default/images/spacer.gif" style="background:url("/e/u261/lang/zh-cn/images/localimage.png") no-repeat center;border:1px solid #ddd;" alt="spacer.gif" />
在主伺服器(192.168.26.210)上建立使用者和密碼:
grant all on *.* to ‘jerry‘@‘192.168.%.%‘ identified by ‘jerrypass‘;
650) this.width=650;" width="572" height="610" src="/e/u261/themes/default/images/spacer.gif" style="background:url("/e/u261/lang/zh-cn/images/localimage.png") no-repeat center;border:1px solid #ddd;" alt="spacer.gif" />
在從伺服器(192.168.26.211)上執行:change master to master_host=‘192.168.26.210‘,master_user=‘jerry‘,master_password=‘jerrypass‘;
650) this.width=650;" width="456" height="330" src="/e/u261/themes/default/images/spacer.gif" style="background:url("/e/u261/lang/zh-cn/images/localimage.png") no-repeat center;border:1px solid #ddd;" alt="spacer.gif" />
啟動從伺服器處理序:start slave;
650) this.width=650;" width="464" height="338" src="/e/u261/themes/default/images/spacer.gif" style="background:url("/e/u261/lang/zh-cn/images/localimage.png") no-repeat center;border:1px solid #ddd;" alt="spacer.gif" />
在第二台從伺服器(192.168.26.212)上執行:change master to master_host=‘192.168.26.210‘,master_user=‘jerry‘,master_password=‘jerrypass‘;
650) this.width=650;" width="466" height="360" src="/e/u261/themes/default/images/spacer.gif" style="background:url("/e/u261/lang/zh-cn/images/localimage.png") no-repeat center;border:1px solid #ddd;" alt="spacer.gif" />
再執行命令查看從狀態:show slave status\G;
650) this.width=650;" width="428" height="321" src="/e/u261/themes/default/images/spacer.gif" style="background:url("/e/u261/lang/zh-cn/images/localimage.png") no-repeat center;border:1px solid #ddd;" alt="spacer.gif" />
執行啟動從伺服器:start slave;
show slave status\G;
650) this.width=650;" width="561" height="406" src="/e/u261/themes/default/images/spacer.gif" style="background:url("/e/u261/lang/zh-cn/images/localimage.png") no-repeat center;border:1px solid #ddd;" alt="spacer.gif" />
同步成功。
建立資料庫操作測試
我們在主伺服器(192.168.26.210)上建立一個新資料庫看下是否兩台從伺服器(192.168.26.211,192.168.26.212)都能同步成功:
執行:createdatabase bd_jerry;
Show databases;
650) this.width=650;" width="539" height="390" src="/e/u261/themes/default/images/spacer.gif" style="background:url("/e/u261/lang/zh-cn/images/localimage.png") no-repeat center;border:1px solid #ddd;" alt="spacer.gif" />
從伺服器(192.168.26.211)上查看:show databases;
650) this.width=650;" width="592" height="425" src="/e/u261/themes/default/images/spacer.gif" style="background:url("/e/u261/lang/zh-cn/images/localimage.png") no-repeat center;border:1px solid #ddd;" alt="spacer.gif" />
從伺服器(192.168.26.212)上查看:show databses;
650) this.width=650;" width="587" height="426" src="/e/u261/themes/default/images/spacer.gif" style="background:url("/e/u261/lang/zh-cn/images/localimage.png") no-repeat center;border:1px solid #ddd;" alt="spacer.gif" />
測試成功。
本文出自 “在路上” 部落格,請務必保留此出處http://jdonghong.blog.51cto.com/3473478/1842832
MYSQL一主多從配置