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

 

replicationslave端还有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,但可以加通配符