
- Learn MySQL
- MySQL - Home
- MySQL - Introduction
- MySQL - Installation
- MySQL - Administration
- MySQL - PHP Syntax
- MySQL - Connection
- MySQL - Create Database
- MySQL - Drop Database
- MySQL - Select Database
- MySQL - Data Types
- MySQL - Create Tables
- MySQL - Drop Tables
- MySQL - Insert Query
- MySQL - Select Query
- MySQL - Where Clause
- MySQL - Update Query
- MySQL - Delete Query
- MySQL - Like Clause
- MySQL - Sorting Results
- MySQL - Using Join
- MySQL - NULL Values
- MySQL - Regexps
- MySQL - Transactions
- MySQL - Alter Command
- MySQL - Indexes
- MySQL - Temporary Tables
- MySQL - Clone Tables
- MySQL - Database Info
- MySQL - Using Sequences
- MySQL - Handling Duplicates
- MySQL - SQL Injection
- MySQL - Database Export
- MySQL - Database Import
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)
- Related Articles
- Data Replication from SAP PO to SQL Server
- How to prevent a user from accessing a specific schema in MySQL?
- Executing SQL Statements from a Text File on MySQL Client
- Check replication type in MySQL?
- What kind of SQL statements can be used to prepare statements?
- Programming the 8259 with slaves
- Usage of backtick in SQL statements?
- How to grant replication privilege to a database in MySQL?
- Programming the 8259 with no slaves
- What is SQL injection? How can you prevent it?
- How to echo print statements while executing an SQL script?
- MySQL Extensions to Standard SQL
- How to process SQL statements with JDBC explain with an example?
- How to prevent duplicate INSERT in MySQL?
- Using SQL statements in ABAP Programming and Database performance

Advertisements