Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Last night one of the developer ran a wrong mySQL statement (Query inserting a row with duplicate primary key) on master machine. Suddenly the replication to its slave stopped. Slave started writing it to mysql_relay_logs and before we could monitor and fix it, the disk ran out of space.

Master is configured to save bin_logs for last 3 days so we still have not completely lost the replication. Can someone help me fix this mess now.

My Master Status:

*************************** 1. row ***************************
File: mysql-bin.000017
Position: 30844254
1 row in set (0.00 sec)

Slave Status: mysql

*************************** 1. row ***************************
                Master_User: replication_user
                Master_Port: 3306
              Connect_Retry: 60
            Master_Log_File: mysql-bin.000014
        Read_Master_Log_Pos: 61132382
             Relay_Log_File: mysqld-relay-bin.000037
              Relay_Log_Pos: 1405976
      Relay_Master_Log_File: mysql-bin.000014
           Slave_IO_Running: No
          Slave_SQL_Running: No
                 Last_Errno: 1062
                 Last_Error: Error 'Duplicate entry '13676-1-2' for key 1' on query. Default database: 'XXX'. Query: 'YYY'
               Skip_Counter: 0
        Exec_Master_Log_Pos: 1405839
            Relay_Log_Space: 8974037551
            Until_Condition: None
              Until_Log_Pos: 0
         Master_SSL_Allowed: No
      Seconds_Behind_Master: NULL
1 row in set (0.00 sec)

Can someone give me exact commands to make everything back to normal? as I said I am sure we have lost data on slave as it ran out of disk but we must be having data on master.

My next question is: How to ensure this doesnt happen again.

Thanks a ton Sparsh Gupta

share|improve this question
up vote 4 down vote accepted

The straight-forward course of action is to wipe out the data on the slave and start fresh with a new copy of the master. The master can be copied by using mysqldump or through something like rsync. Depending on how large your database is, you may experience downtime. This will always work.

There's a chance that if you clear space off the slave drive you can start replication from where the error occurred by using (from inside mysql):

start slave

If the master's bin.log file is in place, there's a chance the replication will start right up. I haven't had very many experiences where this has happened.

The last time I did this was when a developer added a new table to a database, and didn't create it on the slave first. I created the table and had to use sql_slave_skip_counter to skip over the bits that were lost from the bin.log. I then manually inserted the 20 rows of data I had skipped over.

share|improve this answer

just stop slave, and skip the sql statement that makes duplicate entry using (

mysql> stop slave;
mysql> SET GLOBAL sql_slave_skip_counter = 1;
mysql> start slave;

if the error is different after you are running the above command, just repeat it again until the slave working. but if this way not working, you must recreate slave from beginning.

share|improve this answer

Your Answer


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

Not the answer you're looking for? Browse other questions tagged or ask your own question.