Search code examples
mariadbdatabase-replicationrhel

MariaDB database replication fails with SQL_Errno 1062


I have set up a mariadb replication as per these instructions. Things are working well. Well, mostly working actually, that is. I keep coming up with errors similar to this.

Last_SQL_Error: Error 'Duplicate entry '136-202' for key 'PRIMARY'' on query. Default database: 's7data'. Query: 'INSERT INTO history (uid, nid, timestamp) VALUES ('136', '202', '1446221969')'

and

Last_SQL_Errno: 1062

Last_SQL_Error: Error 'Duplicate entry 'links:main-menu:page:node/128/edit:en:1:1' for key 'PRIMARY'' on query. Default database: 's7data'. Query: 'INSERT INTO cache_menu (cid, serialized, created, expire, data) VALUES ('links:main-menu:page:node/128/edit:en:1:1', '1', '1446222020', '0', 'a:4:{s:9:\"min_depth\";i:1;s:9:\"max_depth\";i:1;s:8:\"expanded\";a:1:{i:0;i:0;}s:12:\"active_trail\";a:1:{i:0;i:0;}}')'

As a stop gap, I've tried running

stop slave; SET GLOBAL sql_slave_skip_counter = 100; start slave;

Which works but the problem will eventually crop up again. Can I skip individual issues?


Solution

  • After re-importing the database dump from the Master

    mysql -u <rootuser> -p database-target < db.dump.sql

    On the master I did a reset master and on the slave I did the

    stop slave; reset slave; change master to .... start slave;

    And finally added the skip duplicates by adding this to the my.cnf file as explained by http://www.ducea.com/2008/02/13/mysql-skip-duplicate-replication-errors/

    slave-skip-errors = 1062