3

AppA stores/retrieves data from dbA.tableA AppB stores/retrieves data from dbB.tableA

tableA definition is the same across these databases. To start with dbB.tableA was copied from dbA.tableA (assuming both had 5 rows).

row6 was created by AppA (say primary key 6) row7 was created by AppB (say primary key 7)

I would like row7 to be copied to dbA.tableA and row6 to dbB.tableA

  1. Is this even possible to setup bi-directional replication, so that the AppA, AppB view the same data at any point in time.
  2. If the primary key is an auto-increment, would it be possible to maintain integrity of data or is there a possibility that there would be collisions on the primary key.
4
  • Are both dbA and dbB in the same physical server? Apr 6, 2013 at 14:36
  • Can you check if Multi master replication would work? dev.mysql.com/doc/refman/5.1/en/…
    – automatem
    Apr 7, 2013 at 17:47
  • @altmannmarcelo dbA and dbB are in different machines. dbA is in RDS and dbB is a non RDS instance
    – Rpj
    Apr 7, 2013 at 18:31
  • @Rpj Are both MySQL ? Apr 8, 2013 at 8:37

1 Answer 1

1

I'm assuming these are different instances of MySQL (most likely on different servers).

You can set up Master-master replication, where dbA is a master of dbB and vice versa.

Then, to avoid auto-increment collisions, set the following in my.cnf on dbA:

auto_increment_increment=2
auto_increment_offset=1

And the following on dbB:

auto_increment_increment=2
auto_increment_offset=2
3
  • @rpj Please note that the increment config will not solve collisions in the case of a deletes/updates, and it can lead to replication breaking and/or having inconsistent data.
    – jynus
    Jul 6, 2014 at 16:35
  • @jynus Do you mean deletes/updates on primary key only? Jul 10, 2014 at 10:58
  • No, simultaneous deletes and updates on the same rows (no matter the field) will break replication as there is no procedure for conflict resolution/rollbacking. Check these slides (specially page 10 and 11): percona.com/live/mysql-conference-2013/sites/default/files/…
    – jynus
    Jul 10, 2014 at 16:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.