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 > all.sql
replica2 % mysql < 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.
Best Answer
Yes that's exactly what the error telling
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 mysqlBut 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 replicateSHOW MASTER STATUS
and copy thefile name
and theposition
UNLOCK TABLES;
In slave
CHANGE MASTER TO MASTER_HOST = 'masterhost', MASTER_USER = 'masteruser', MASTER_PASSWORD = 'masterpass', MASTER_LOG_FILE = 'filename', MASTER_LOG_POS = 'position';
start slave;