Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MySQL Binary Log Replication: Can it be set to ignore errors?

I'm running a master-slave MySQL binary log replication system (phew!) that, for some data, is not in sync (meaning, the master holds more data than the slave). But the slave stops very frequently on the slightest MySQL error, can this be disabled? (perhaps a my.cnf setting for the replicating slave ignore-replicating-errors or some of the sort ;) )

This is what happens, every now and then, when the slave tries to replicate an item that does not exist, the slave just dies. a quick check at SHOW SLAVE STATUS \G; gives

       Slave-IO-Running: Yes
      Slave-SQL-Running: No
        Replicate-Do-DB: 
             Last-Errno: 1062
             Last-Error: Error 'Duplicate entry '15218' for key 1' on query. Default database: 'db'. Query: 'INSERT INTO db.table ( FIELDS ) VALUES ( VALUES )'

which I promptly fix (once I realize that the slave has been stopped) by doing the following:

STOP SLAVE;
RESET SLAVE;
START SLAVE;

... lately this has been getting kind of tiresome, and before I spit out some sort of PHP which does this for me, i was wondering if there's some my.cnf entry which will not kill the slave on the first error.

Cheers,

/mp

like image 391
mauriciopastrana Avatar asked Aug 27 '08 17:08

mauriciopastrana


People also ask

Which of the following replication methods must be preferred?

Row-based replication is the default choice since MySQL 5.7.

How do I stop binary logs in MySQL?

To disable the MySQL Binary Logging, you can use the --skip-log-bin or --disable-log-bin option at startup.

What is the purpose of binary log?

The purpose of the binary log is to allow replication, where data is sent from one or more masters to one or more slave servers based on the contents of the binary log, as well as assisting in backup operations. A MariaDB server with the binary log enabled will run slightly more slowly.


2 Answers

stop slave; set global sql_slave_skip_counter=1; start slave;

You can ignore only the current error and continue the replication process.

like image 60
shantanuo Avatar answered Sep 21 '22 23:09

shantanuo


Yes, with --slave-skip-errors=xxx in my.cnf, where xxx is 'all' or a comma sep list of error codes.

like image 37
tessein Avatar answered Sep 19 '22 23:09

tessein