1

MySQL master has a table Products that has triggers on update and delete. Deleted/Updated records are stored in ProductsUpdatedDeleted tab.

When a record is deleted, the operation is replicated to the slave server. The issue is that slave also executes the trigger thus adding a record in its ProductsUpdatedDeleted table. Then a duplicate record in ProductsUpdatedDeleted received from the master server through replication.

What is the best way to stop the slave to execute triggers? I can comment trigger code in the slave but I would prefer both servers in the same state to quick failover.

RolandoMySQLDBA
185k34 gold badges327 silver badges541 bronze badges
asked Oct 24, 2017 at 14:48

1 Answer 1

0

Basically, there are two methods

METHOD #1

Use row-based replication. It says so in Paragraphs 1-3 of "Replication and Triggers"

With statement-based replication, triggers executed on the master also execute on the slave. With row-based replication, triggers executed on the master do not execute on the slave. Instead, the row changes on the master resulting from trigger execution are replicated and applied on the slave.

This behavior is by design. If under row-based replication the slave applied the triggers as well as the row changes caused by them, the changes would in effect be applied twice on the slave, leading to different data on the master and the slave.

If you want triggers to execute on both the master and the slave—perhaps because you have different triggers on the master and slave—you must use statement-based replication. However, to enable slave-side triggers, it is not necessary to use statement-based replication exclusively. It is sufficient to switch to statement-based replication only for those statements where you want this effect, and to use row-based replication the rest of the time.

METHOD #2

Drop all the triggers on the Slave. No trigger present, no trigger to execute.

Do not do both method. Just select one method.

answered Oct 24, 2017 at 15:22
4
  • I guess I will comment code inside triggers on slave. Commented Oct 24, 2017 at 20:02
  • Hey, commenting out the code inside all Slave Triggers is a third method. Commented Oct 24, 2017 at 20:04
  • Yes. Because if I delete, I will forget later which triggers were there and how to recode them :-) But there are many of them. Wish there was an option in mysql not to execute triggers in slave machine. Commented Oct 24, 2017 at 20:08
  • 1
    Actually, this is not an issue at all. in Row based replication, triggers are not executed on slaves. They are executed in statement based replication. Without this master master or group replication would never work. Commented Dec 15, 2017 at 4:25

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.