Maison > Article > base de données > 深入浅出MySQL双向复制技能
配置MySQL数据同步(单向双向)由于公司的业务需求,须要网通和电信的数据同步,就做了个MySQL的双向同步,记下流程,以后用得到再翻出来,也贴出来供大家参考。 一、准备服务器 由于MySQL不同版本之间的(二进制日志)binlog格式可能会不一样,因此最好的搭配
# Replication Master Server (default)<br><br># binary logging is required for replication
log-bin=/var/log/mysql/updatelog<br><br>server-id = 1<br><br>binlog-do-db=test<br><br>binlog-ignore-db=mysql<br><br>
GRANT REPLICATION SLAVE,RELOAD,SUPER, ON *.* TO back@192.168.0.2 IDENTIFIED BY 'back' ;<br><br>FLUSH PRIVILEGES ;<br><br>2、配置
同步Slave<br><br>修改f文件,添加<br><br>server-id = 2<br><br>master-host = 192.168.0.1<br><br>master-user = back<br><br>master-password = back<br><br>master-port = 3306<br><br>replicate-ignore-db=mysql (我的是Ver 14.14 Distrib 5.1.22-rc版,这个参数好像用不上)<br><br>replicate-do-db=test
show master status;
+------------------+----------+-------------------+------------------+<br><br> File Position Binlog_Do_DB Binlog_Ignore_DB <br><br>+------------------+----------+-------------------+------------------+<br><br> updatelog.000028 313361 test mysql <br><br>+------------------+----------+-------------------+------------------+
slave stop;<br><br>CHANGE MASTER TO MASTER_LOG_FILE='updatelog.000028',MASTER_LOG_POS=313361;<br><br>slave start;<br><br>用show slave statusG;看一下从服务器的同步情况<br><br>Slave_IO_Running: Yes<br><br>Slave_SQL_Running: Yes
log-bin=/var/log/mysql/updatelog<br><br>binlog-do-db=test<br><br>binlog-ignore-db=mysql
GRANT REPLICATION SLAVE,RELOAD,SUPER, ON *.* TO back@192.168.0.1 IDENTIFIED BY 'back' ;<br><br>FLUSH PRIVILEGES ;
master-host = 192.168.0.2<br><br>master-user = back<br><br>master-password = back<br><br>master-port = 3306<br><br>replicate-ignore-db=mysql<br><br>replicate-do-db=test
show master status;<br><br>+------------------+----------+-------------------+------------------+<br><br> File Position Binlog_Do_DB Binlog_Ignore_DB <br><br>+------------------+----------+-------------------+------------------+<br><br> updatelog.000028 13753 test mysql <br><br>+------------------+----------+-------------------+------------------+
slave stop;<br><br>CHANGE MASTER TO MASTER_LOG_FILE='updatelog.000028',MASTER_LOG_POS=13753;<br><br>slave start;