標籤:mysql 生產情境 讀寫分離
MYSQL生產情境讀寫分離
M --------à S
單向同步為保持資料一致性,只能在M上寫入資料
方法:
1、從庫,串連使用者授權上控制
2、Web程式寫指向主,讀指向從
3、讓從庫只能讀不能寫(read-only)
生產授權方案1:
主庫:grant select,delete,insert,update on *.*to [email protected]’%’ identified by ‘dongliqiang’;
從庫:grant select on *.* to [email protected]’%’ identifiedby ‘dongliqiang’;
my.cnf 忽略授權表
binlog-ignore-db=mysql
binlog-ignore-db=information_schema
binlog-ignore-db=performance_schema
生產授權方案2:
主庫:grant select,delete,insert,update on *.*to [email protected]’%’ identified by ‘dongliqiang’;
從庫:grant select,delete,insert,update on *.*to [email protected]’%’ identified by ‘dongliqiang’;
REVOKE update,insert,delete on *.* [email protected]’%’;
生產授權方案3:
主庫:grant select,delete,insert,update on *.*to [email protected]’%’ identified by ‘dongliqiang’;
從庫:grant select,delete,insert,update on *.*to [email protected]’%’ identified by ‘dongliqiang’;
REVOKE update,insert,delete on *.* [email protected]’%’;
從庫my.cnf設定檔增加read-only或者在啟動mysql時增加-—read-only參數
[mysqld]
read-only
replication的slave端還有6個參數
1、--replication-do-db 設定需要複製的資料庫以逗號(,)分割
2、--replication-ignore-db 設定需要排除的資料庫以逗號(,)分割
3、--replication-do-table 設定需要複製的表以逗號(,)分割
4、--replication-ignore-table 設定需要排除的表以逗號(,)分割
5、--replication-wild-do-db 等同於1,但可以加萬用字元
6、--replication-wild-ignore-db等同於2,但可以加萬用字元
本文出自 “董利強” 部落格,請務必保留此出處http://6207422.blog.51cto.com/6197422/1978796
MYSQL生產情境讀寫分離