Take the 2-minute tour ×
Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. It's 100% free, no registration required.

A MySQL v5.1.61 relay got corrupted when the machine suddenly shut down. I tried to fix it but it didn't work.
— How do I fix it? Did I do something wrong?

As far as I've read, corrupted MySQL relay logs are easily fixed:

change master to master_log_file='<Relay_Master_Log_File>',
                 master_log_pos=<Exec_Master_Log_Pos>;

where Relay_Master_Log_File and Exec_Master_Log_Pos are listed by:
mysql> show slave status;

However when I did change master status ..., I got a primary key violation error. How is that possible? Is the above procedure no correct, or is e.g. some +1 missing?

(For now I've simply re-imported a --master-data mysqldump from the master to the slave, and this solved the problem. However, in the future, doing that might not be appropriate.)


Here follows details about my particular problem:

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.

And this is what I did:

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;

And this is what happened, a PK error:

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

I think I followed the recommended procedure (see links just below), still there was a PK error :-( ? http://bugs.mysql.com/bug.php?id=26489, search for "Workarounds". http://mhbarr.wordpress.com/2013/07/26/mysql-slave-corrupted-relay-log/ http://stackoverflow.com/a/14438408

share|improve this question
    
Please mention the precise (major.minor.release) versions of MySQL server that you are running on both master and slave... just in case there are any version-specific issues, here, that could have contributed to the original problem. –  Michael - sqlbot Nov 25 '13 at 13:22
    
Hi @Michael-sqlbot, I updated the question with the exact version number, which is 5.1.61 on both master and slave. Thanks for your comment, I'm actually interpreting it as a little indication that what I did ought to have worked :-) :-( –  KajMagnus Nov 25 '13 at 14:13
1  
Yes, it looks like it should have worked, and actually it looks like it probably actually did work, as perhaps the original relay log, before the corrupt section, had already done the insert at that master log position, but couldn't advance the displayed master position to the next pointer, since that pointer is stored in the relay log (which was corrupt.) So you might have gotten away with skipping that event and moving to the next event, then verifying that master and slave actually had identical data... I haven't had an opportunity to review the question in sufficient detail, yet. –  Michael - sqlbot Nov 25 '13 at 15:09
    
Thanks @Michael-sqlbot, then I think that if this problem happens again, I'll do SET GLOBAL sql_slave_skip_counter = 1; START SLAVE; and skip one event on the slave, and hope that helps — does that make sense? If it doesn't help (if there's still a PK error), I'll import a dump with --master-data again. –  KajMagnus Nov 25 '13 at 15:44

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.