Kaj*_*nus 30 mysql replication corruption
当机器突然关闭时,MySQL v5.1.61 中继被损坏。我试图修复它,但没有奏效。
- 我如何解决它?我做错什么了吗?
据我所知,损坏的 MySQL 中继日志很容易修复:
change master to master_log_file='<Relay_Master_Log_File>',
master_log_pos=<Exec_Master_Log_Pos>;
Run Code Online (Sandbox Code Playgroud)
其中Relay_Master_Log_File和Exec_Master_Log_Pos由以下列出:
mysql> show slave status;
但是,当我这样做时change master status ...,我收到了主键违规错误。这怎么可能?上述程序是否不正确,或者例如缺少一些+1?
(现在我只是将 --master-data mysqldump 从主服务器重新导入到从服务器,这解决了问题。但是,在将来,这样做可能不合适。)
以下是有关我的特定问题的详细信息:
mysql> show slave status \G
*************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: the-master-host
Master_User: replication
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: mysql-bin.000021
Read_Master_Log_Pos: 33639968
Relay_Log_File: mysql-relay-bin.000271
Relay_Log_Pos: 2031587
Relay_Master_Log_File: mysql-bin.000020
Slave_IO_Running: Yes
Slave_SQL_Running: No
Replicate_Do_DB: the_database
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
Exec_Master_Log_Pos: 66395191
Relay_Log_Space: 36559177
Until_Condition: None
Until_Log_File:
Until_Log_Pos: 0
Master_SSL_Allowed: No
Master_SSL_CA_File:
Master_SSL_CA_Path:
Master_SSL_Cert:
Master_SSL_Cipher:
Master_SSL_Key:
Seconds_Behind_Master: NULL
Master_SSL_Verify_Server_Cert: No
Last_IO_Errno: 0
Last_IO_Error:
Last_SQL_Errno: 1594
Last_SQL_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.
Run Code Online (Sandbox Code Playgroud)
这就是我所做的:
mysql> stop slave;
mysql> reset slave;
mysql> change master to master_host='the-master-host', master_user='replication', master_password='the-password', master_log_file='mysql-bin.000020', master_log_pos=66395191;
mysql> start slave;
Run Code Online (Sandbox Code Playgroud)
这就是发生的事情,一个 PK 错误:
131122 15:17:29 [Note] Slave I/O thread: connected to master 'replication@the-master-host:3306',replication started in log 'mysql-bin.000020' at position 66395191
131122 15:17:29 [ERROR] Slave SQL: Error 'Duplicate entry '71373' for key 'PRIMARY'' on query. Default database: 'the_database'. Query: 'insert into ... values ...', Error_code: 1062
131122 15:17:29 [Warning] Slave: Data truncated for column 'date' at row 1 Error_code: 1265
131122 15:17:29 [Warning] Slave: Duplicate entry '71373' for key 'PRIMARY' Error_code: 1062
Run Code Online (Sandbox Code Playgroud)
我想我遵循了推荐的程序(请参阅下面的链接),但仍然存在 PK 错误 :-( ? http://bugs.mysql.com/bug.php?id=26489,搜索“解决方法” 。http: //mhbarr.wordpress.com/2013/07/26/mysql-slave-corrupted-relay-log/ /sf/answers/1010688591/
小智 40
错误:Last_SQL_Errno:1594 Last_SQL_Error:中继日志读取失败:无法解析中继日志事件条目。
此错误意味着主日志文件已损坏或中继日志文件已损坏。
首先在从站上运行“show slave status \G”并注意:
Master_Log_File: mysql-bin.000026
Read_Master_Log_Pos: 2377104
Relay_Log_File: mysqld-relay-bin.000056
Relay_Log_Pos: 1097303
Relay_Master_Log_File: mysql-bin.000026
Exec_Master_Log_Pos: 1097157
Run Code Online (Sandbox Code Playgroud)
首先我们要确保主日志文件是完整的,所以跳转到主服务器并找到Relay_Master_Log_File(检查/var/log/mysql)并运行以下命令:
mysqlbinlog mysql-bin.000026
Run Code Online (Sandbox Code Playgroud)
将显示日志,但希望您不会看到任何错误消息。如果您看到错误消息,则说明主日志已损坏,您可能必须重新映像。
接下来在从中继日志上运行相同的命令(通常在 /var/lib/mysql 中)
mysqlbinlog mysqld-relay-bin.000056
Run Code Online (Sandbox Code Playgroud)
您可能会看到一些错误显示已停止复制的损坏,如下所示:
ERROR: Error in Log_event::read_log_event(): 'read error', data_len: 336, event_type: 2
ERROR: Could not read entry at offset 1097414: Error in log format or read error.
DELIMITER ;
# End of log file
ROLLBACK /* added by mysqlbinlog */;
/*!50003 SET COMPLETION_TYPE=@OLD_COMPLETION_TYPE*/;
/*!50530 SET @@SESSION.PSEUDO_SLAVE_MODE=0*/;
root@db:/var/lib/mysql#
Run Code Online (Sandbox Code Playgroud)
如果您看到任何错误,那么主服务器上的日志没有问题,只有从服务器的中继日志损坏。这是个好消息,我们可以重置从站并告诉它主站的详细信息以及从哪里继续。如果你没有看到任何错误,那么现在停止阅读,你有一个不同的问题。
如果slave中继日志有错误,执行以下命令重置slave,损坏日志重新连接master,获取ok日志,重新开始slaving。请注意, MASTER_LOG_POS 是Exec_Master_Log_Pos,而 MASTER_LOG_FILE 是Relay_Master_Log_File(不是第一个,它匹配已获取并需要丢弃的中继日志)都来自第一个命令。
mysql> stop slave;
Query OK, 0 rows affected (0.14 sec)
mysql> reset slave all;
Query OK, 0 rows affected (0.43 sec)
mysql> CHANGE MASTER TO MASTER_HOST='master.host.com', MASTER_USER='masteruser', MASTER_PASSWORD='masterpass', MASTER_LOG_FILE='mysql-bin.000026', MASTER_LOG_POS=1097157;
Query OK, 0 rows affected (0.93 sec)
mysql> start slave;
Query OK, 0 rows affected (0.00 sec)
Run Code Online (Sandbox Code Playgroud)
Moh*_*yas 12
[修复从服务器的中继日志损坏后的 MySQL 复制]
从站(版本 5.XX)上的 MySQL 复制已停止。Slave_IO_Running 被标记为 Yes,但 Slave_SQL_Running 被标记为 No。简单的停止/启动 slave 没有帮助,所以需要进一步的问题分析。似乎当前从站的中继日志已损坏,因为使用“mysqlbinlog”进行测试已打印出错误。因此,解决方案是丢弃当前的中继 binlog,并将 slave 指向最后一个 master binlog 位置。
要修复错误,应丢弃从站上的当前 binlog 文件并设置新位置。在设置新的 binlog 位置之前,使用命令SHOW SLAVE STATUS \G记住来自损坏的从服务器的Relay_Master_Log_File和Exec_Master_Log_Pos值很重要:
Run Code Online (Sandbox Code Playgroud)Relay_Master_Log_File: mysql-bin.002045 Exec_Master_Log_Pos: 103641119好的,有了这个值,可以设置新的 binlog 位置:
Run Code Online (Sandbox Code Playgroud)# stop slave mysql> stop slave; # make slave forget its replication position in the master's binary log mysql> reset slave; # change slave to start reading from stopped position mysql> change master to master_log_file='mysql-bin.002045', master_log_pos=103641119; # start slave mysql> start slave;请注意,这
reset slave将删除master.info,relay-log.info以及所有中继日志文件,因此不需要清理/var/lib/mysql目录中的剩余部分。
| 归档时间: |
|
| 查看次数: |
67073 次 |
| 最近记录: |