MySQL 複製:是否可以暫時阻止某些 SQL 語句複製到從屬資料庫?
要實現此功能,你需要將 sql_log_bin 設定為 0。為了理解這個概念,讓我們建立一個表。建立表的查詢如下
mysql> create table SQLStatementsDemo -> ( -> UserId int NOT NULL AUTO_INCREMENT PRIMARY KEY, -> UserName varchar(20) -> ); Query OK, 0 rows affected (0.79 sec)
使用 insert 命令在表中插入一些記錄。查詢如下 −
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)使用 select 語句顯示錶中的所有記錄。查詢如下 −
mysql> select *from SQLStatementsDemo;
以下是輸出
+--------+----------+ | UserId | UserName | +--------+----------+ | 1 | John | | 2 | Carol | | 3 | Bob | | 4 | Mike | | 5 | Sam | | 6 | David | +--------+----------+ 6 rows in set (0.00 sec)
以下查詢實現了 SQL 語句的 MySQL 複製
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)
廣告
資料結構
網路
RDBMS
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
JavaScript
PHP