I am trying using MySQL Replication Listener Library to do data replication between HostA and HostB.
Basiclly it's just like doing row-based replication, but by myself other than mysql. Reading all row changes from HostA's bin log and applying all these changes to HostB.
The issue I am encountering is, I am not able to disable triggers temporarily, which causes the data to be out of sync.
Take an example, suppose the database to be synchronized is TestSyncDB, and there are two tables in it which are Data and DataOp. The Data table has a trigger with it and once a record is inserted into this table, the trigger will generate a new record to the DataOp.
Now a new record is inserted into HostA.TestSyncDB.Data, since there is a trigger, so there will actually be two records adding to the tables, and the Replication Listener Library will return to me two queries, something like:
- insert into HostA.TestSyncDB.Data values (...)
- insert into HostA.TestSyncDB.DataOp values (...) // by trigger
The problem is if I replay these two queries to HostB, there will be three new records added to tables in HostA.TestSyncDB, because of the triggers. Then data is never right ever after.
So how to solve this? Is is possible to disable triggers temporarily? If not, how to do it correctly like what MySQL Replication does?