Unsupported Screen Size: The viewport size is too small for the theme to render properly.

Sync Databases With Overlapping Primary Keys

forums forums SQLyog Sync tools, Migration, Scheduled Backup and Notifications Sync Databases With Overlapping Primary Keys

  • This topic is empty.
Viewing 0 reply threads
  • Author
    Posts
    • #30604
      peterlaursen
      Participant

      Please details “it errors out on duplicate primary key entries”.  Exactly what error do you get?

      It he problem is that for rows with identical PK-values 'source will overwrite target' then we have replied to this questions many times now.  The purpose of a PK is and always was to identify rows uniquely. All reasonable sync tools assume this and even the SQL language itself does in some contexts (example:  INSERT ..  ON DUPLICATE KEY …).  Sync'ing means “making identically identified rows identical”.  In that case you will need to define the PK in such a way that the same PK-value is not created on different hosts. At least two ways to do this:

      1) Add a column to each table, make it constant on each host (ie: define a DEFAULT) but different between hosts.  Add that column to the PK.

      2) Define auto_increment_increment and auto_increment_offset server variables so that auto_increment values will be created as even values on one host and odd values on the other (or start with “1” on one server and “1000000” on the other. This requires of course that the PK is an autoincrement column.

      If you have started collecting data both solutions will require some work – in particular if you have Foreign Keys to the PK.

Viewing 0 reply threads
  • You must be logged in to reply to this topic.