问题一:Error connecting to source 'slave@127.0.0.1:3307'. This was attempt 3/86400, with a delay of 30 seconds between attempts. Message: Can't connect to MySQL server on '127.0.0.1:3307' (111)
就是因为这个ip不对,导致的异常。
解决方式:
切换到从数据库中,停止同步主数据库数据
#停止从数据库同步主数据库
stop slave;
在从数据库中,更换ip,配置主从复制
change master to \
master_host='192.168.199.153',master_user='slave',master_password='root', \
master_port=3307,master_log_file='mall-mysql-bin.000001', \
master_log_pos=1200,master_connect_retry=30;
切换到主数据库中,进行配置:
#删除原来的slave用户
drop user 'slave'@'%';
#再次创建slave同步数据用户
create user 'slave'@'%' identified with mysql_native_password by 'root';
# 给用户slave授权
grant replication slave,replication client on *.* to 'slave'@'%';
在从数据库中,开启主从复制
start slave;
再次切换到从数据库中,查看状态
show slave status \G;
问题二:Got fatal error 1236 from source when reading data from binary log: 'log event entry exceeded max_allowed_packet; Increase max_allowed_packet on source; the first event 'mall-mysql-bin.000001' at 893, the last event read from './mall-mysql-bin.000001' at 126, the last byte read from './mall-mysql-bin.000001' at 912.'
这个错误就是,在同步的时候,没有找到二进制文件的偏移量导致的。
解决办法:
在主数据库查看状态,并重置主库的值,再查状态
show master status;
flush logs;
show master status;
去从库停止主从复制
stop slave;flush privileges;
在从库中重新配置主从复制,并开启主从复制
这里的偏移量来自于主库的Position的值
#配置主从复制
change master to \
master_host='192.168.199.153',master_user='slave',master_password='root', \
master_port=3307,master_log_file='mall-mysql-bin.000001', \
master_log_pos=157,master_connect_retry=30;#开启主从复制
start slave;
最后,在主库建库建表及数据,都会同步到从库中。这里就不做展示了。