标签:
实验机:两台
IP:192.168.1.5 192.168.1.10
操作系统:Linux RedHat 6.5
Mysql版本:5.6.31
# vim /etc/my.cnf
#log_slave_updates 注释掉这行
server-id=1 将id号改为1
#:vim /etc/my.cnf
#log_slave_updates 注释掉这行
server-id=2 #将server_id改为2
主从(操作):
mysql>reset master;
mysql>reset slave all;
~~~~~~~~~~~~~192.168.1.5~~~~~~~~~~~~~~~~
做主:
grant replication slave on *.* to ‘losnau‘@‘192.168.1.%‘ identified by ‘losnau‘; #给13slave进行授权复制
mysql>flush tables with read lock;
mysql>show master status;
mysql>unlock tables;
做从
change master to master_host=‘192.168.1.5‘,master_user=‘losnau‘,master_password=‘losnau‘, master_log_file=‘mysql-bin.000001‘,master_log_pos=120;
mysql>start slave;
mysql>show slave status\G;
~~~~~~~~~~~~~~192.168.1。10~~~~~~~~~~~~~~~~~~~
做主
grant replication slave on *.* to ‘losnau‘@‘192.168.1.%‘ identified by ‘losnau‘; #给13slave进行授权复制
mysql>flush tables with read lock;
mysql>show master status;
mysql>unlock tables;
做从
change master to master_host=‘192.168.1.10‘,master_user=‘losnau‘,master_password=‘losnau‘, master_log_file=‘mysql-bin.000001‘,master_log_pos=120;
mysql>start slave;
mysql>show slave status\G;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1. 一般的异常只需要跳过一步即可恢复
模拟故障,创建主从复制之前.在主上创建一个CC库,
在开启主从复制,从的IO都是为YES后,在主上创建一个gongda库,看看从库是否同步成功?
如果成功,接下来模拟故障.在主上将CC删除掉.在从看slave状态是不是就开始报错了??
解决方法如下:
> stop slave;
>SET GLOBAL sql_slave_skip_counter = 1; 遇到错误直接跳过,继续恢复
> start slave;
2.断电导致主从不能同步时,通主库的最后一个bin-log日志进行恢复
在主库服务器上,mysqlbinlog mysql-bin.xxxx > binxxxx.txt
tail -n 100000 binxxxx.txt > tail-binxxxx.txt
vim tail-binxxxx.txt 打开tail-binxxxx.txt文件找到最后一个postion值
然后在从库上,change host to 相应正确的值
>stop slave;
>change master to master_host=‘ip‘, master_user=‘username‘, master_password=‘password‘, master_log_file=‘mysql-bin.xxxx‘, master_log_pos=xxxx;
>start slave;
>show slave status\G;
3.主键冲突、表已存在等错误代码如1062,1032,1060等,可以在mysql主配置文件指定
略过此类异常并继续下条sql同步,这样也可以避免很多主从同步的异常中断
[mysqld]
slave-skip-errors = 1062,1032,1060
标签:
原文地址:http://www.cnblogs.com/losbyday/p/5813774.html