2

My question is regarding Master-Slave replication on MySQL using linux server.

I am just testing something on replication in MySQL, I am wondering is it possible to prevent the slave from replicating delete statements?

I know the slave will replicate all inserts/deletes from the master. But I only want it to replicate the inserts.

Is this possible?

jeffry
  • 327
  • 2
  • 8
  • 23

2 Answers2

2

Refer this:

There are several ways to do this.

  1. Run SET SQL_LOG_BIN=0; for the relevant session on the master before executing your delete. That way it is not written to the binary log
  2. Implement a BEFORE DELETE trigger on the slave to ignore the deletes.

    use approach #1 for statements that I don't want to replicate. It requires SUPER privilege.

Community
  • 1
  • 1
Sathish D
  • 4,854
  • 31
  • 44
  • ok i want this to be done automatically, how do you propose i go about implementing approach 2? – jeffry Mar 13 '14 at 12:25
  • 2
    #2 is not possible. You can't stop an action within a query via a trigger without throwing an exception, which should in turn stop replication... and triggers on the slave do not fire anyway, for row-based binary log events, because the row changes that were caused by the trigger firing on the master are sent to the slave as row changes and the trigger action on the slave would be redundant. – Michael - sqlbot Mar 13 '14 at 18:15
0

Well it can be done:

  • using the SET SQL_LOG_BIN=0; for the delete session on the master before executing your delete. So will prevent from written to the binary log
  • Implement BEFORE DELETE/UPDATE/INSERT triggers on the slave tables to ignore the deletes.
    Same rule applies to any of the statement !
Up_One
  • 5,213
  • 3
  • 33
  • 65