Replicating from MySQL 5.1 master to 5.6 slave failing because 'INSERT ... VALUES (NOW())' results in 'Error_code: 1062' I am migrating away from some old MySQL 5.1 servers to some new MySQL 5.6 servers. During this process, I'm creating a new MySQL 5.6 slave from an existing MySQL 5.1 slave, using the procedure in the mysqldump reference guide.

For example, if my MySQL 5.1 servers are named 'master1' and 'replica1' and I have a new MySQL 5.6 server named 'replica2', the following should make replica2 a second slave of 'master1':

replica2 % mysqldump --login-path=replica1 --all-databases --dump-slave --include-master-host-port --apply-slave-statements --lock-all-tables  --add-drop-database &gt; all.sql
replica2 % mysql &lt; all.sql


And this seems work well, but replication fails with the following error complaining about duplicate entries for the primary key.

2015-06-12 10:00:00 1234 [ERROR] Slave SQL: Worker 0 failed executing transaction '' at master log mysql-bin.009332, end_log_pos 12341234; Error 'Duplicate entry '8072' for key 'PRIMARY'' on query. Default database: 'DATABASE'. Query: 'INSERT INTO "Member" ("Created") VALUES (NOW())', Error_code: 1062


Can I assume that 'INSERT INTO "Member" ("Created") VALUES (NOW())' is triggering the error here? Can I get replication to work without skipping rows with SET GLOBAL sql_slave_skip_counter = 1;?

Some additional details:


I'm using classic MySQL replication, and GTIDs are currently disabled.
The MySQL 5.1 servers are using STATEMENT-based replication, but the new MySQL 5.6 servers are using ROW-based replication.
I don't own the application code, and I cannot change the SQL.
Can I assume that 'INSERT INTO "Member" ("Created") VALUES (NOW())' is
  triggering the error here?


Yes that's exactly what the error telling

Error 'Duplicate entry '8072' for key 'PRIMARY'' on query. 
Default database: 'DATABASE'. Query: 'INSERT INTO "Member" ("Created") VALUES (NOW())', 
Error_code: 1062



  Can I get replication to work without skipping rows with SET GLOBAL
  sql_slave_skip_counter = 1;?


Yes, You can go and delete the row with the ID 8072 in the table.. you can add the option of slave-skip-errors = 1062 in my.cnf and restart mysql

But you have to be extremely wary about doing this, as the referential integrity is there for a reason, and without it, your slave could not be satisfactorily promoted to take the place of the master in the case of something going wrong with your master hardware...

The only clean way is:

In the master 


You FLUSH TABLES WITH READ LOCK; in the database you want to
replicate
SHOW MASTER STATUS and copy the file name and the position
Excute a full backup to the database you want to replicate
Then release the tables with UNLOCK TABLES;


In slave


Restore the databse
Excute this CHANGE MASTER TO MASTER_HOST = 'masterhost', MASTER_USER
= 'masteruser', MASTER_PASSWORD = 'masterpass', MASTER_LOG_FILE = 'filename', MASTER_LOG_POS = 'position';
Then start slave;