mysql 双向主从_MySQL 主从双向同步

主库:my.cnf

server-id=1  ######只能有一个server-id

log-bin=MySQL-bin

master-host     =  192.168.0.121

master-user     =   copy  ###授权远程连接

master-password =  1

master-port     =  3306

从库:my.cnf

server-id=2  ######只能有一个server-id

log-bin=slave-bin

master-host     =  192.168.0.120

master-user     =   copy  ###授权远程连接

master-password =  1

master-port     =  3306

主从/usr/local/mysql/bin/mysql -uroot -p1

mysql>reset master   ######重置所有binlog日志

mysql>show slave status;

Slave_IO_State: Waiting for master to send event

Master_Host: 192.168.0.120

Master_User: copy

Master_Port: 3306

Connect_Retry: 60   ####闲置时定期同步

Master_Log_File: mysql-bin.000002

Read_Master_Log_Pos: 106   ######同步的pos位置

Relay_Log_File: localhost-relay-bin.000005

Relay_Log_Pos: 251

Relay_Master_Log_File: mysql-bin.000002

Slave_IO_Running: Yes  ####必须是yes

Slave_SQL_Running: Yes ####必须是yes

Replicate_Do_DB:

Replicate_Ignore_DB:

若同步不成功试着删除所有同步有关数据

/etc/init.d/mysql stop

rm -rf   /usr/local/mysql/var /localhost-relay-bin.* master.info  mysql-bin.* relay-log.info

/etc/init.d/mysql start

同步成功后主从重启等等一般不会造成同步不成功的问题0b1331709591d260c1c78e86d0c51c18.png

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值