Sunday, April 29, 2012

How to resync MySQL Replication after updated master database

After update the table structure in master database, the slave stopping replication. After update the mysqldump with -d  for the new database to slave machine, it report duplicate entry error.

You can using following commands to fix it: (source: http://forums.mysql.com/read.php?26,24736,24884#msg-24884)

mysql> SET GLOBAL SQL_SLAVE_SKIP_COUNTER = 1; 
mysql> START SLAVE; 

Use the value 1 for any SQL statement that does not use AUTO_INCREMENT or LAST_INSERT_ID(), otherwise you will need to use the value 2. Statements that use AUTO_INCREMENT or LAST_INSERT_ID() take up 2 events in the binary log.