SET GLOBAL SQL_SLAVE_SKIP_COUNTER
<
文中的意思是當master傳到slave的語句中要用到auto_increment,或者last_insert_id()時,需要skip兩個event. 但實際情況並非如此
-------------------quote begin------------------------
3. If you decide that you can skip the next statement from the master, issue the following
statements:
mysql> SET GLOBAL SQL_SLAVE_SKIP_COUNTER = n;
mysql> START SLAVE;
The value of n should be 1 if the next statement from the master does not use
AUTO_INCREMENT or LAST_INSERT_ID(). Otherwise, the value should be 2. The
reason for using a value of 2 for statements that use AUTO_INCREMENT or
LAST_INSERT_ID() is that they take two events in the binary log of the master.
-------------------quote end------------------------
測試過程如下:
172.16.161.26 為master
172.16.161.15 為slave
同步c2cdb,初始狀態ok
$ /usr/local/mysql/bin/mysql -uroot -pxxx c2cdb -s -e "show slave status\G" |egrep "Slave_IO_Running|Sl
ave_SQL_Running"
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
1. 在master上建立測試表
mysql> create table tmp_test_0208(id int not null auto_increment,name varchar(30),primary key(id)) engine=innodb;
Query OK, 0 rows affected (0.20 sec)
2, 在salve上insert 3條記錄
mysql> insert into tmp_test_0208 values(1,'a'),(2,'b'),(3,'c');
Query OK, 3 rows affected (0.00 sec)
Records: 3 Duplicates: 0 Warnings: 0
mysql> select * from tmp_test_0208;
+----+------+
| id | name |
+----+------+
| 1 | a |
| 2 | b |
| 3 | c |
+----+------+
3 rows in set (0.00 sec)
3, 在master上insert 3條記錄
mysql> insert into tmp_test_0208(name) values('a'),('b'),('c');
Query OK, 3 rows affected (0.02 sec)
Records: 3 Duplicates: 0 Warnings: 0
mysql> select * from tmp_test_0208;
+----+------+
| id | name |
+----+------+
| 1 | a |
| 2 | b |
| 3 | c |
+----+------+
3 rows in set (0.00 sec)
4, slave 的sql thread 中止
/usr/local/mysql/bin/mysql -uroot -pxxx c2cdb -s -e "show slave status\G" |egrep "Slave_IO_Running|Sl
ave_SQL_Running"
Slave_IO_Running: Yes
Slave_SQL_Running: No
5, skip next statemate後start slave正常
mysql> SET GLOBAL SQL_SLAVE_SKIP_COUNTER = 1 ;
Query OK, 0 rows affected (0.00 sec)
mysql> slave start;
Query OK, 0 rows affected (0.00 sec)
/usr/local/mysql/bin/mysql -uroot -pxxx c2cdb -s -e "show slave status\G" |egrep "Slave_IO_Running|Sl
ave_SQL_Running"
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
slave端errlog如下:
070208 16:07:59 [ERROR] Slave: Error 'Duplicate entry '1' for key 1' on query. Default database: 'c2cdb'. Query: 'insert into tmp_te
st_0208(name) values('a'),('b'),('c')', Error_code: 1062
070208 16:07:59 [ERROR] Error running query, slave SQL thread aborted. Fix the problem, and restart the slave SQL thread with "SLAVE
START". We stopped at log 'db_auction1-bin.000203' position 14215101
070208 16:09:59 [Note] Slave SQL thread initialized, starting replication in log 'db_auction1-bin.000203' at position 14215101, rela
y log './db_auction1_b-relay-bin.000457' position: 200682931
master羰binlog中相應的記錄如下:
# at 14215101
#070208 16:08:00 server id 1 log_pos 14215101 Intvar
SET INSERT_ID=1;
# at 14215129
#070208 16:08:00 server id 1 log_pos 14215129 Query thread_id=2744782 exec_time=0 error_code=0
SET TIMESTAMP=1170922080;
insert into tmp_test_0208(name) values('a'),('b'),('c');
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/94384/viewspace-600279/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- @@GLOBAL.GTID_PURGED can only be set when @@GLOBAL.GTID_EXECUTED is empty
- MySQL 透過set global設定變數的注意點MySql變數
- sql_slave_skip_counterSQL
- ERROR 1840 (HY000) at line 24: @@GLOBAL.GTID_PURGED can only be set when @@GLOBAError
- SCSS !globalCSS
- 4.4global
- JavaScript Global 物件JavaScript物件
- Deep Global Registration
- GLOBAL TEMPORARY TABLE(轉)
- Codeforces Global Round 26
- Codeforces Global Round 27
- Codeforces Global Round 13
- Python GIL(Global Interpreter Lock)Python
- [Vue] Provide and Inject Global StorageVueIDE
- Codeforces Global Round 26 (A - D)
- set /?
- Set
- lombok get/set 與 JavaBean get/setLombokJavaBean
- Synced Global AI Weekly | 2018.10.20—10.26AI
- Synced Global AI Weekly | 2018.10.6—10.12AI
- Synced Global AI Weekly | 2018.10.27—11.2AI
- NodeJS require a global module/package in linuxNodeJSUIPackageLinux
- Synced Global AI Weekly | 2018.8.4—8.10AI
- Synced Global AI Weekly | 2018.9.8—9.14AI
- Synced Global AI Weekly | 2018.9.15—9.21AI
- vim之強大的global
- [Javascript] Perform Set Operations using JavaScript Set MethodsJavaScriptORM
- Jet Set
- set -o
- set -e
- Vue.set與vue.$set的使用Vue
- 訓練集(train set),驗證集(validation set)和測試集(test set)AI
- 正規表示式 global屬性
- 正規表示式 global 屬性
- Synced Global AI Weekly | 2018.6.23-6.29AI
- MySQL5.7 Waiting for global read lockMySqlAI
- python中global是什麼意思?Python
- alter system set event和set events的區別
- Set 和Map