mysql 双向同步
1.在两台mysql上创建用户,设置权限 A上添加: grant replication slave,replication client,reload,super on *.* to ‘sync_user‘@‘192.168.2.220‘ identified by ‘123456‘ with grant option;//用于B访问 B上: grant replication slave,replication client,reload,super on *.* to ‘sync_user‘@‘192.168.2.67‘ identified by ‘123456‘ with grant option;//用于A访问 执行 #flush privileges; 更新数据库使用户生效。 create database testsync; use testsync; create table t_user ( id int primary key auto_increment, username varchar(20), age int ); 在[mysqld]下面添加以下配置 # test synchronized at 67 log-bin server-id = 1 master-host =192.168.2.220 master-user =sync_user master-pass =123456 master-port =3306 master-connect-retry =60 replicate-do-db =testsync replicate-do-db =testsync2 replicate-ignore-db =mysql,information_schema,performance_schema auto_increment_increment=1 # test synchronized at 220 log-bin server-id = 2 master-host =192.168.2.67 master-user =sync_user master-pass =123456 master-port =3306 master-connect-retry =60 replicate-do-db =testsync replicate-do-db =testsync2 replicate-ignore-db =mysql,information_schema,performance_schema auto_increment_increment=2 show processlist; insert into t_user values(null, ‘frank‘, 23); select * from t_user; server-id= 2 binlog-do-db=happy binlog-do-db=ipaddressmgr replicate-do-db=happy replicate-do-db=ipaddressmgr replicate-ignore-db=mysql,information_schema,performance_schema log-slave-updates slave-skip-errors=all sync_binlog=1 auto_increment_increment=2 auto_increment_offset=2
log-bin server-id= 1 binlog-do-db=happy binlog-do-db=ipaddressmgr replicate-do-db=happy replicate-do-db=ipaddressmgr replicate-ignore-db=mysql,information_schema,performance_schema log-slave-updates slave-skip-errors=all sync_binlog=1 auto_increment_increment=2 auto_increment_offset=1
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。