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)
广告