国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 數據庫 > MySQL > 正文

MySQL中主從復制重復鍵問題修復方法

2024-07-24 13:06:38
字體:
來源:轉載
供稿:網友

這篇文章主要介紹了MySQL中主從復制重復鍵問題修復,需要的朋友可以參考下

-------------------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------------------------

MySQL文檔中的意思是當master傳到slave的語句中要用到auto_increment,或者last_insert_id()時,需要skip兩個event. 但實際情況并非如此

測試過程如下: 172.16.161.26 為master 172.16.161.15 為slave 同步c2cdb,初始狀態ok

1. 在master上創建測試表
 

  1. mysql> create table tmp_test_0208(id int not null auto_increment,name varchar(30),primary key(id)) engine=innodb; 
  2. Query OK, 0 rows affected (0.20 sec) 

2, 在salve上insert 3條記錄

  1. mysql> insert into tmp_test_0208 values(1,'a'),(2,'b'),(3,'c'); 
  2. Query OK, 3 rows affected (0.00 sec) 
  3. Records: 3 Duplicates: 0 Warnings: 0 
  4.  
  5. mysql> select * from tmp_test_0208; 
  6. +----+------+ 
  7. | id | name | 
  8. +----+------+ 
  9. | 1 | a | 
  10. | 2 | b | 
  11. | 3 | c | 
  12. +----+------+ 
  13. rows in set (0.00 sec) 


3, 在master上insert 3條記錄

  1. mysql> insert into tmp_test_0208(namevalues('a'),('b'),('c'); 
  2. Query OK, 3 rows affected (0.02 sec) 
  3. Records: 3 Duplicates: 0 Warnings: 0 
  4.  
  5. mysql> select * from tmp_test_0208; 
  6. +----+------+ 
  7. | id | name | 
  8. +----+------+ 
  9. | 1 | a | 
  10. | 2 | b | 
  11. | 3 | c | 
  12. +----+------+ 
  13. rows in set (0.00 sec) 


4, slave 的sql thread 中止

  1. /usr/local/mysql/bin/mysql -uroot -pxxx c2cdb -s -e "show slave status/G" |egrep "Slave_IO_Running|Sl 
  2. ave_SQL_Running" 
  3. Slave_IO_Running: Yes 
  4. Slave_SQL_Running: No 


5, skip next statemate后start slave正常
 

  1. mysql> SET GLOBAL SQL_SLAVE_SKIP_COUNTER = 1 ; 
  2. Query OK, 0 rows affected (0.00 sec) 
  3.  
  4. mysql> slave start; 
  5. Query OK, 0 rows affected (0.00 sec) 
  6.  
  7. /usr/local/mysql/bin/mysql -uroot -pxxx c2cdb -s -e "show slave status/G" |egrep "Slave_IO_Running|Sl 
  8. ave_SQL_Running" 
  9. Slave_IO_Running: Yes 
  10. 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');

總結:使用SET GLOBAL SQL_SLAVE_SKIP_COUNTER 命令跳過失敗的SQL

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 乐昌市| 崇文区| 海丰县| 桂东县| 余干县| 南澳县| 绥棱县| 洞口县| 清原| 康乐县| 罗城| 电白县| 荆门市| 台北县| 苍溪县| 龙海市| 霍城县| 阳信县| 兴城市| 韶关市| 婺源县| 泰兴市| 桑植县| 北流市| 河南省| 锦屏县| 察隅县| 冷水江市| 恩平市| 德钦县| 盱眙县| 新竹市| 财经| 孝义市| 思茅市| 叶城县| 囊谦县| 普宁市| 佛冈县| 乌兰察布市| 栾川县|