MySQL replication: temporarily prevent specific SQL statements replicating to the slaves?


To achieve this, you need to set sql_log_bin to 0. To understand the concept, let us create a table. The query to create a table is as follows

mysql> create table SQLStatementsDemo
   -> (
   -> UserId int NOT NULL AUTO_INCREMENT PRIMARY KEY,
   -> UserName varchar(20)
   -> );
Query OK, 0 rows affected (0.79 sec)

Insert some records in the table using insert command. The query is as follows −

mysql> insert into SQLStatementsDemo(UserName) values('John');
Query OK, 1 row affected (0.18 sec)
mysql> insert into SQLStatementsDemo(UserName) values('Carol');
Query OK, 1 row affected (0.14 sec)
mysql> insert into SQLStatementsDemo(UserName) values('Bob');
Query OK, 1 row affected (0.14 sec)
mysql> insert into SQLStatementsDemo(UserName) values('Mike');
Query OK, 1 row affected (0.14 sec)
mysql> insert into SQLStatementsDemo(UserName) values('Sam');
Query OK, 1 row affected (0.14 sec)
mysql> insert into SQLStatementsDemo(UserName) values('David');
Query OK, 1 row affected (0.14 sec)

Display all records from the table using select statement. The query is as follows −

mysql> select *from SQLStatementsDemo;

The following is the output

+--------+----------+
| UserId | UserName |
+--------+----------+
|      1 | John     |
|      2 | Carol    |
|      3 | Bob      |
|      4 | Mike     |
|      5 | Sam      |
|      6 | David    |
+--------+----------+
6 rows in set (0.00 sec)

Here are the queries implementing MySQL replication for SQL statements

mysql> SET sql_log_bin=0;
Query OK, 0 rows affected (0.00 sec)
mysql> update SQLStatementsDemo set UserName='Maxwell' where UserId=6;
Query OK, 1 row affected (0.05 sec)
Rows matched: 1 Changed: 1 Warnings: 0
mysql> select *from SQLStatementsDemo;
+--------+----------+
| UserId | UserName |
+--------+----------+
|      1 | John     |
|      2 | Carol    |
|      3 | Bob      |
|      4 | Mike     |
|      5 | Sam      |
|      6 | Maxwell  |
+--------+----------+
6 rows in set (0.00 sec)
mysql> insert into SQLStatementsDemo(UserName) values('Chris');
Query OK, 1 row affected (0.16 sec)
mysql> select *from SQLStatementsDemo;
+--------+----------+
| UserId | UserName |
+--------+----------+
|      1 | John     |
|      2 | Carol    |
|      3 | Bob      |
|      4 | Mike     |
|      5 | Sam      |
|      6 | Maxwell  |
|      7 | Chris    |
+--------+----------+
7 rows in set (0.00 sec)
mysql> delete from SQLStatementsDemo where UserId=7;
Query OK, 1 row affected (0.10 sec)
mysql> SET sql_log_bin=1 ;
Query OK, 0 rows affected (0.00 sec)

Updated on: 30-Jul-2019

63 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements