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