MYSQL生產場景讀寫分離
MYSQL生產場景讀寫分離
M --------à S
單向同步為保持數據一致性,只能在M上寫入數據
方法:
1、從庫,連接用戶授權上控制
2、Web程序寫指向主,讀指向從
3、讓從庫只能讀不能寫(read-only)
生產授權方案1:
主庫:grant select,delete,insert,update on *.*to rep@’%’ identified by ‘dongliqiang’;
從庫:grant select on *.* to rep@’%’ 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 rep@’%’ identified by ‘dongliqiang’;
從庫:grant select,delete,insert,update on *.*to rep@’%’ identified by ‘dongliqiang’;
REVOKE update,insert,delete on *.* fromdonglq@’%’;
生產授權方案3:
主庫:grant select,delete,insert,update on *.*to rep@’%’ identified by ‘dongliqiang’;
從庫:grant select,delete,insert,update on *.*to rep@’%’ identified by ‘dongliqiang’;
REVOKE update,insert,delete on *.* fromdonglq@’%’;
從庫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生產場景讀寫分離