MySQL复制:暂时阻止特定的SQL语句复制到从属服务器?
为此,您需要将sql_log_bin设置为0。为了理解这一概念,让我们创建一个表。创建表的查询如下
mysql> create table SQLStatementsDemo -> ( -> UserId int NOT NULL AUTO_INCREMENT PRIMARY KEY, -> UserName varchar(20) -> );
使用insert命令在表中插入一些记录。查询如下-
mysql> insert into SQLStatementsDemo(UserName) values('John'); mysql> insert into SQLStatementsDemo(UserName) values('Carol'); mysql> insert into SQLStatementsDemo(UserName) values('Bob'); mysql> insert into SQLStatementsDemo(UserName) values('Mike'); mysql> insert into SQLStatementsDemo(UserName) values('Sam'); mysql> insert into SQLStatementsDemo(UserName) values('David');
使用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; mysql> update SQLStatementsDemo set UserName='Maxwell' where UserId=6; 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'); 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; mysql> SET sql_log_bin=1 ;