I have been looking for a way to prevent MySQL delete statements from getting processed by the slave, I'm working on data warehousing project, and I would like to delete data from production server after having data replicated to slave.
what is the best way to get this done?
Thank you
There are several ways to do this.
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 logBEFORE DELETE
trigger on the slave to ignore the deletes.I tend to use approach #1 for statements that I don't want to replicate. It requires SUPER
privilege.
I have not tried #2, but it should be possible.
You'll only be able to achieve this with a hack, and it will likely cause problems. MySQL replication isn't designed for this.
Imagine you insert a record in your master, it replicates to the slave. You then delete from the master, but it doesn't delete from the slave. If someone adds a record with the same unique key, there will be a conflict on the slave.
Some alternatives:
Perhaps if you provide the reason you want this mirror database without deletes, I could give you a more targeted solution.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With