水电工888 发表于 2018-10-7 10:21:31

MYSQL生产场景读写分离

  MYSQL生产场景读写分离
  M --------à S
  单向同步为保持数据一致性,只能在M上写入数据
  方法:
  1、从库,连接用户授权上控制
  2、Web程序写指向主,读指向从
  3、让从库只能读不能写(read-only)
  生产授权方案1:

  主库:grant select,delete,insert,update on *.*to rep@’%’>
  从库:grant select on *.* to rep@’%’>  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@’%’>
  从库:grant select,delete,insert,update on *.*to rep@’%’>  REVOKE update,insert,delete on *.* fromdonglq@’%’;
  生产授权方案3:

  主库:grant select,delete,insert,update on *.*to rep@’%’>
  从库:grant select,delete,insert,update on *.*to rep@’%’>  REVOKE update,insert,delete on *.* fromdonglq@’%’;
  从库my.cnf配置文件增加read-only或者在启动mysql时增加-—read-only参数
  
  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,但可以加通配符

页: [1]
查看完整版本: MYSQL生产场景读写分离