erwann le guevedec
erwann le guevedec

Reputation: 31

How to resolve MySQL and FK réplication problem?

I'm looking to create a replication server. Dump is ok, database master too. I imported dump but replication doesn't work.

here is the slave status :

*************************** 1. row ***************************
                Slave_IO_State:
                   Master_Host: 192.168.0.100
                   Master_User: replica
                   Master_Port: 35120
                 Connect_Retry: 60
               Master_Log_File: mysql-bin.000004
           Read_Master_Log_Pos: 842296279
                Relay_Log_File: mysqld-relay-bin.000002
                 Relay_Log_Pos: 1937
         Relay_Master_Log_File: mysql-bin.000004
              Slave_IO_Running: No
             Slave_SQL_Running: No
               Replicate_Do_DB:
           Replicate_Ignore_DB:
            Replicate_Do_Table:
        Replicate_Ignore_Table:
       Replicate_Wild_Do_Table:
   Replicate_Wild_Ignore_Table:
                    Last_Errno: 1452
                    Last_Error: Could not execute Write_rows event on table pipo.HistoPT; Cannot add or update a child row: a foreign key constraint fails (`pipo`.`HistoPT`, CONSTRAINT `FK_HistoPT_histo` FOREIGN KEY (`histoIdProduct`, `histoRank`) REFERENCES `histo` (`idProduct`, `rank`) ON DELETE NO ACTION ON UPDATE NO ACTIO), Error_code: 1452; handler error HA_ERR_NO_REFERENCED_ROW; the event's master log mysql-bin.000004, end_log_pos 840556447
                  Skip_Counter: 1
           Exec_Master_Log_Pos: 840555497
               Relay_Log_Space: 1608175
               Until_Condition: None
                Until_Log_File:
                 Until_Log_Pos: 0
            Master_SSL_Allowed: No
            Master_SSL_CA_File:
            Master_SSL_CA_Path:
               Master_SSL_Cert:
             Master_SSL_Cipher:
                Master_SSL_Key:
         Seconds_Behind_Master: NULL
 Master_SSL_Verify_Server_Cert: No
                 Last_IO_Errno: 0
                 Last_IO_Error:
                Last_SQL_Errno: 1452
                Last_SQL_Error: Could not execute Write_rows event on table pipo.HistoPT; Cannot add or update a child row: a foreign key constraint fails (`pipo`.`HistoPT`, CONSTRAINT `FK_HistoPT_histo` FOREIGN KEY (`histoIdProduct`, `histoRank`) REFERENCES `histo` (`idProduct`, `rank`) ON DELETE NO ACTION ON UPDATE NO ACTIO), Error_code: 1452; handler error HA_ERR_NO_REFERENCED_ROW; the event's master log mysql-bin.000004, end_log_pos 840556447
   Replicate_Ignore_Server_Ids:
              Master_Server_Id: 1
                Master_SSL_Crl:
            Master_SSL_Crlpath:
                    Using_Gtid: No
                   Gtid_IO_Pos:
       Replicate_Do_Domain_Ids:
   Replicate_Ignore_Domain_Ids:
                 Parallel_Mode: optimistic
                     SQL_Delay: 0
           SQL_Remaining_Delay: NULL
       Slave_SQL_Running_State:
              Slave_DDL_Groups: 0
Slave_Non_Transactional_Groups: 0
    Slave_Transactional_Groups: 0
1 row in set (0.000 sec)

I don't know what I have to change. especially since the master base is in production, so impossible to modify it (and anyway, it works very well) Does someone can help me ?

Upvotes: 1

Views: 1203

Answers (1)

SebastianX
SebastianX

Reputation: 209

First disable the FK, see below

SET FOREIGN_KEY_CHECKS=0
... import it ...
SET FOREIGN_KEY_CHECKS=1

Upvotes: 1

Related Questions