mysql复制报错案例一例
之前遇到的一个主从复制的报错问题,虽然解决的过程比较快,但是我感觉还是有一定的借鉴意义,遇到类似的错误code,大家可以参考一下:
错误信息如下:
Slave_IO_Running: Yes Slave_SQL_Running: No Replicate_Do_DB: Replicate_Ignore_DB: Replicate_Do_Table: Replicate_Ignore_Table: Replicate_Wild_Do_Table: Replicate_Wild_Ignore_Table: Last_Errno: 1594 Last_Error: Relay log read failure: Could not parse relay log event entry. The possible reasons are: the master's binary log is corrupted (you can check this by running 'mysqlbinlog' on the binary log), the slave's relay log is corrupted (you can check this by running 'mysqlbinlog' on the relay log), a network problem, or a bug in the master's or slave's MySQL code. If you want to check the master's binary log or slave's relay log, you will be able to know their names by issuing 'SHOW SLAVE STATUS' on this slave. Skip_Counter: 0
从错误的类型上看,应该是从库找不到对应的relay log的事件了,造成这样的问题有很多,错误信息中给了4种提示:
1、master的binlog出现问题
2、slace的binlog出现问题
3、网络问题
4、可能是master或者slave中MySQL 源码的bug(倒是供认不讳啊~~~)
这给了我一点提醒,因为这台机器昨天刚刚做过磁盘扩容,因为是个从库,所以直接进行了停机扩容,随后进行了MySQL的实例重启,可能停机扩容再重启对实例产生了一定的影响。。。(至于什么影响?我想最有可能的是配置文件参数的变更吧)
怎么办呢???用网管思维先解决一下:
"网管,这台机器有问题,来看看",
"重启试一下",
"重启了,不行",
"换个机器吧"
先尝试重启复制,如下:
stop slave;start slave;show slave statusG
还是不行,但是报错信息改变了:
Slave_IO_Running: Yes Slave_SQL_Running: No Replicate_Do_DB: Replicate_Ignore_DB: Replicate_Do_Table: Replicate_Ignore_Table: Replicate_Wild_Do_Table: Replicate_Wild_Ignore_Table: Last_Errno: 1593 Last_Error: Error initializing relay log position: Could not find target log file mentioned in relay log info in the index file './relay-bin.index' during relay log initialization Skip_Counter: 0
这个提示信息看意思是说没有找到目标的relay log index文件,index文件是定义在指定目录里面的,查看了主从库的relay-log文件路径(虽然主库上没有relay log),相关参数如下:
主库 mysql:(none) 09:42:05>>show variables like '%relay%'; +-----------------------+--------------------------------------------+ | Variable_name | Value | +-----------------------+--------------------------------------------+ | max_relay_log_size | 0 | | relay_log | /data/mysql_3306/log/slave-relay-bin | | relay_log_index | /data/mysql_3306/log/slave-relay-bin.index | | relay_log_info_file | relay-log.info | | relay_log_purge | ON | | relay_log_recovery | OFF | | relay_log_space_limit | 0 | +-----------------------+--------------------------------------------+ 7 rows in set (0.00 sec) 从库 mysql:(none) 09:46:32>>show variables like '%relay%'; +---------------------------+----------------+ | Variable_name | Value | +---------------------------+----------------+ | max_relay_log_size | 0 | | relay_log | | | relay_log_basename | | | relay_log_index | | | relay_log_info_file | relay-log.info | | relay_log_info_repository | FILE | | relay_log_purge | ON | | relay_log_recovery | OFF | | relay_log_space_limit | 0 | +---------------------------+----------------+ 9 rows in set (0.00 sec)
可以看到,从库上没有配置相关的relay log路径,于是使用find的linux命令找到了从库的relay-bin.index文件所在位置,是默认放在了/data文件夹下面,看来上面的报错和relay log的文件位置有点关系。
鉴于上述原因,我们需要利用IO线程重新生成相应的relay log来在从库应用,于是使用了下面的方法在从库进行修复:
1、reset slave;
2、记录相应的偏移量master_log_file和read_master_log_pos
3、重新使用change master语句和上面记录的偏移量进行复制
4、start slave;重启复制关系即可