HiveBrain v1.2.0
Get Started
← Back to all entries
patternsqlModerate

How would I run DELETE queries on a Master Without Executing Same DELETEs on a Slave?

Submitted by: @import:stackexchange-dba··
0
Viewed 0 times
withoutexecutingsamedeleteslavedeleteswouldmasterhowqueries

Problem

If I want to run a query that will only execute on the master mysql server and not the slave. assuming we have an environment with replication through query logs. Could I and how?

The idea is to have some records that are archived on the slave. Lets say the master is a production website and only requires data that has been entered in the past month to operate correctly but the slave is where data from years will be saved and later analyzed to change variable on the main (production/master) server.

Solution

There is a much, much simpler way

A Replication Slave relies on the Master's binary logs so as to ship SQL from them into the Slave's local relay logs. Just tell the Master not to record the SQL

SQLSTMT="SET SQL_LOG_BIN=0;"
SQLSTMT="${SQLSTMT} DELETE FROM tablename WHERE column='our filters'"
mysql -u... -p... -Ae"${SQLSTMT}"


The key here is to disable binary logging in its session. The Slave won't know what hit the Master because the Master will execute the DELETE and not record the DELETE.

Give it a Try !!!

Code Snippets

SQLSTMT="SET SQL_LOG_BIN=0;"
SQLSTMT="${SQLSTMT} DELETE FROM tablename WHERE column='our filters'"
mysql -u... -p... -Ae"${SQLSTMT}"

Context

StackExchange Database Administrators Q#20020, answer score: 11

Revisions (0)

No revisions yet.