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
http://ylw6006.blog.51cto.com/470441/888523
时间: 2024-10-27 18:30:50