1. 程式人生 > >mysql開啟GTID跳過錯誤的方法

mysql開啟GTID跳過錯誤的方法

1、資料庫版本

mysql> select version()
    -> ;
+-------------------------------------------+
| version()                                 |
+-------------------------------------------+
| 5.7.17                                  |
+-------------------------------------------+
1 row in set (0.00 sec)

--主從同步

10.10.6.87  主

10.10.90 從

2、產生問題過程

(1)主從庫開啟了GTID模式

(2)在從庫某表添加了唯一索引,然後去主庫給某表新增索引,導致問題 (此處為了測試,故意為之,製造問題)

 'Duplicate key name 'i_index'' on query. Default database: 'test'. Query: 'create unique index i_index on t(id)'
 (3) 檢視從庫狀態,發現Slave_SQL_Running: No
mysql> show slave status \G;
*************************** 1. row ***************************
               Slave_IO_State: Waiting for master to send event
                  Master_Host: 10.10.6.87
                  Master_User: rep
                  Master_Port: 3306
                Connect_Retry: 60
              Master_Log_File: mysql-bin.000028
          Read_Master_Log_Pos: 1113
               Relay_Log_File: mysql-bin.000007
                Relay_Log_Pos: 1151
        Relay_Master_Log_File: mysql-bin.000028
             Slave_IO_Running: Yes
            Slave_SQL_Running: No
              Replicate_Do_DB: 
          Replicate_Ignore_DB: mysql,information_schema
           Replicate_Do_Table: 
       Replicate_Ignore_Table: 
      Replicate_Wild_Do_Table: 
  Replicate_Wild_Ignore_Table: 
                   Last_Errno: 1061
                   Last_Error: Error 'Duplicate key name 'i_index'' on query. Default database: 'test'. Query: 'create unique index i_index on t(id)'
                 Skip_Counter: 0
          Exec_Master_Log_Pos: 938
              Relay_Log_Space: 2301
              Until_Condition: None
               Until_Log_File: 
                Until_Log_Pos: 0
           Master_SSL_Allowed: No
           Master_SSL_CA_File: 
           Master_SSL_CA_Path: 
              Master_SSL_Cert: 
            Master_SSL_Cipher: 
               Master_SSL_Key: 
        Seconds_Behind_Master: NULL
Master_SSL_Verify_Server_Cert: No
                Last_IO_Errno: 0
                Last_IO_Error: 
               Last_SQL_Errno: 1061
               Last_SQL_Error: Error 'Duplicate key name 'i_index'' on query. Default database: 'test'. Query: 'create unique index i_index on t(id)'
  Replicate_Ignore_Server_Ids: 
             Master_Server_Id: 2
                  Master_UUID: 8f9e146f-0a18-11e7-810a-0050568833c8
             Master_Info_File: /var/lib/mysql/master.info
                    SQL_Delay: 0                                            #SQL延遲同步
          SQL_Remaining_Delay: NULL
      Slave_SQL_Running_State: 
           Master_Retry_Count: 86400
                  Master_Bind: 
      Last_IO_Error_Timestamp: 
     Last_SQL_Error_Timestamp: 170421 15:44:05
               Master_SSL_Crl: 
           Master_SSL_Crlpath: 
           Retrieved_Gtid_Set: 8f9e146f-0a18-11e7-810a-0050568833c8:1-4
            Executed_Gtid_Set: 8f9e146f-0a18-11e7-810a-0050568833c8:1-3,     #多出了一個GTID(本身例項執行的事務)
f7c86e19-24fe-11e7-a66c-005056884f03:1-9
                Auto_Position: 0
         Replicate_Rewrite_DB: 
                 Channel_Name: 
           Master_TLS_Version: 
1 row in set (0.00 sec)


ERROR: 
No query specified


3、解決問題過程:


mysql> stop slave sql_thread;
Query OK, 0 rows affected, 1 warning (0.00 sec)


mysql> set global sql_slave_skip_counter=1;
ERROR 1858 (HY000): sql_slave_skip_counter can not be set when the server is running with @@GLOBAL.GTID_MODE = ON. Instead, for each transaction that you want to skip, generate an empty transaction with the same GTID as the transaction
mysql> stop slave;
Query OK, 0 rows affected (0.01 sec)


mysql> set global sql_slave_skip_counter=1;
ERROR 1858 (HY000): sql_slave_skip_counter can not be set when the server is running with @@GLOBAL.GTID_MODE = ON. Instead, for each transaction that you want to skip, generate an empty transaction with the same GTID as the transaction


從上面可以發現按照往常解決辦法,是行不通的,因為開啟了GTID原因




3.1 分析出現問題時候GTID值

通過分析法獲取gtid值 

通過檢視mysql> show slave status \G;

檢視一下資訊並記錄下來:
 Retrieved_Gtid_Set: 8f9e146f-0a18-11e7-810a-0050568833c8:1-4  --跳過此事務  
Executed_Gtid_Set: 8f9e146f-0a18-11e7-810a-0050568833c8:1-3,f7c86e19-24fe-11e7-a66c-005056884f03:1-9

通過上面的資訊可以知道已經執行的gtid是8f9e146f-0a18-11e7-810a-0050568833c8:1-3,準備要執行8f9e146f-0a18-11e7-810a-0050568833c8:4的時候出問題了,所以條跳過此步驟




或者 通過日誌檢視  (推薦)


#170421 15:36:28 server id 2  end_log_pos 938 CRC32 0x9f9f38d8 Xid = 140
COMMIT/*!*/;
# at 938
#170421 15:39:10 server id 2  end_log_pos 1003 CRC32 0x20f00692 GTIDlast_committed=3sequence_number=4
SET @@SESSION.GTID_NEXT= '8f9e146f-0a18-11e7-810a-0050568833c8:4'/*!*/;
# at 1003
#170421 15:39:10 server id 2  end_log_pos 1113 CRC32 0x4b10f015 Querythread_id=25420exec_time=0error_code=0
use `test`/*!*/;
SET TIMESTAMP=1492760350/*!*/;
create unique index i_index on t(id)
/*!*/;
SET @@SESSION.GTID_NEXT= 'AUTOMATIC' /* added by mysqlbinlog */ /*!*/;
DELIMITER ;
# End of log file
/*!50003 SET [email protected]_COMPLETION_TYPE*/;
/*!50530 SET @@SESSION.PSEUDO_SLAVE_MODE=0*/;

解決辦法一:跳過錯誤

(1)停止slave程序

mysql> STOP SLAVE;

(2)設定事務號,事務號從Retrieved_Gtid_Set獲取

在session裡設定gtid_next,即跳過這個GTID

mysql> SET @@SESSION.GTID_NEXT= '8f9e146f-0a18-11e7-810a-0050568833c8:4'

(3)設定空事物

mysql> BEGIN; COMMIT;

(4)恢復事物號

mysql> SET SESSION GTID_NEXT = AUTOMATIC;

(5)啟動slave程序

mysql> START SLAVE;

解決辦法二:重置master方法跳過錯誤


mysql>  STOP SLAVE;
mysql> RESET MASTER;
mysql>   SET @@GLOBAL.GTID_PURGED ='8f9e146f-0a18-11e7-810a-0050568833c8:1-4'
mysql>  START SLAVE;


上面這些命令的用意是,忽略8f9e146f-0a18-11e7-810a-0050568833c8:1-4 這個GTID事務,下一次事務接著從 5 這個GTID開始,即可跳過上述錯誤。

解決辦法三:使用pt-slave-restart工具


pt-slave-restart工具的作用是監視某些特定的複製錯誤,然後忽略,並且再次啟動SLAVE程序(Watch and restart MySQL replication after errors)。
忽略所有1062錯誤,並再次啟動SLAVE程序
[[email protected] mysql]# pt-slave-resetart -S /var/lib/mysql/mysql.sock —error-numbers=1062


檢查到錯誤資訊只要包含 test.t1,就一概忽略,並再次啟動 SLAVE 程序
[[email protected] mysql]# pt-slave-resetart -S /var/lib/mysql/mysql.sock  —error-text=”test.t1”


下面舉例解決錯誤問題號
            Last_SQL_Error: Could not execute Delete_rows event on table test.t; Can't find record in 't', Error_code: 1032; handler error HA_ERR_KEY_NOT_FOUND; the event's master log mysql-bin.000028, end_log_pos 1862
  Replicate_Ignore_Server_Ids: 
             Master_Server_Id: 2
                  Master_UUID: 8f9e146f-0a18-11e7-810a-0050568833c8
             Master_Info_File: /var/lib/mysql/master.info
                    SQL_Delay: 0
          SQL_Remaining_Delay: NULL
      Slave_SQL_Running_State: 
           Master_Retry_Count: 86400
                  Master_Bind: 
      Last_IO_Error_Timestamp: 
     Last_SQL_Error_Timestamp: 170421 17:45:11
               Master_SSL_Crl: 
           Master_SSL_Crlpath: 
           Retrieved_Gtid_Set: 8f9e146f-0a18-11e7-810a-0050568833c8:1-7
            Executed_Gtid_Set: 8f9e146f-0a18-11e7-810a-0050568833c8:1-6,
f7c86e19-24fe-11e7-a66c-005056884f03:1
                Auto_Position: 0
         Replicate_Rewrite_DB: 
                 Channel_Name: 
           Master_TLS_Version: 
1 row in set (0.00 sec)


[[email protected] mysql]# pt-slave-restart  -S  /var/lib/mysql/mysql.sock   --error-numbers=1032   --user=root --password='bc.123456'
2017-04-21T17:53:27 S=/var/lib/mysql/mysql.sock,p=...,u=root mysql-bin.000015         620 1032 
2017-04-21T17:54:31 S=/var/lib/mysql/mysql.sock,p=...,u=root mysql-bin.000015        1140 1032 




引數解釋:
 --slave-password=s     Sets the password to be used to connect to the slaves
  --slave-user=s         Sets the user to be used to connect to the slaves
  --sleep=i              Initial sleep seconds between checking the slave ( default 1)
  --socket=s         -S  Socket file to use for connection=
--password=s       -p  Password to use when connecting
pt-slave-resetart  -S./mysql.sock —error-numbers=1032
 --error-numbers=h      Only restart this comma-separated list of errors
 --host=s           -h  Connect to host
 --user=s           -u  User for login if not current user



相關推薦

mysql開啟GTID錯誤方法

1、資料庫版本 mysql> select version()     -> ; +-------------------------------------------+ | version()                                

mysql使用GTID事務

GTID跳過有兩種方法,一種是普通的跳過一個事務的方法,另外一個是在基於主庫搭建新的slave的時候. 一、普通跳過一個事務的方法。 通過show slave status\G找到衝突的GTID號. 然後執行 SET gtid_next = '衝突的GTID號'; BEGIN;COMMIT; SET

Mysql-GTID複製錯誤方法

gtid複製出現錯誤是個比較麻煩的問題,需要人工處理,如果直接跳過可能導致資料丟失或者資料不一致的情況,所以建議人工處理。下面我來介紹Mysql gtid複製出現錯誤的情況,按照下來方式處理前必需找出錯誤的sql和錯誤的資料,處理完成前將資料修改成為一致資料。

MySQL GTID複製Slave錯誤事務Id以及複製排錯問題總結

GTID複製典型的複製錯誤有兩種:1,資料物件級別的錯誤,包括主庫上update的資料在從庫上不存在,主從逐漸衝突,庫表索引等物件的衝突等等,   如果是純粹的跳過錯誤的話,這一類的錯誤需要跳過思路是找到主庫binlog中對應的事務Id然後在從庫上跳過即可。2,日誌找不到的錯誤,也即從庫在執行利用主庫上的

mysql主從復制錯誤

ren class 結果 test mysql gin ack table .cn mysql主從復制,經常會遇到錯誤而導致slave端復制中斷,這個時候一般就需要人工幹預,跳過錯誤才能繼續跳過錯誤有兩種方式:1.跳過指定數量的事務:mysql>slave stop;

mysql主從復制錯誤

host count mes use 中斷 兩種 ssl p s pda mysql主從復制,經常會遇到錯誤而導致slave端復制中斷,這個時候一般就需要人工幹預,跳過錯誤才能繼續 1 跳過錯誤有兩種方式: 1.1 跳過指定數量的事務: mysql>stop slav

MySQL開啟記錄執行的SQL語句方法

開啟方法很簡單:編輯/etc/my.cnf檔案,在[mysqld]節下面新增:log=/var/lib/mysql/sql_row.log行(日誌的路徑自己根據需要定義)。 [mysqld] datadir=/var/lib/mysql socket=/var/lib/

MySQL5.6 GTID模式,同步複製報錯不能解決方法

搭建虛擬機器centos6.0, mysql5.6.10主從複製,死活不同步,搞了一整天找到這篇文章。終於OK了。 資料庫版本: mysql> select version();  +------------+  | version()  |  +----------

MySql開啟GTID和多線程復制功能

shu _for 默認 參數 verify nlog p s recover ret 1.修改參數 master: gtid_mode = ON --開啟gtid這個必須打開 enforce-gtid-consistency =

打正式包的時候錯誤檢查

build.gradle下的android中加入如下的話就可以了 但是是極其不建議加的  我之所以發這個部落格 是因為有人加在了我接手的專案上  我怎麼在relase下執行也不報錯 這樣寫的程式是有b

關於idea錯誤編譯的理解

其實idea使用eclipse編譯器可以實現跳過報錯的程式碼啟動專案去debug測試其他正常的程式碼,做法是before launch只選擇build,no error check注意不能同時選擇build artifacts ,因為tomcat實際上執行的就是artifac

解決Navicat for MySQL開啟連線時出現錯誤提示1045 access denied for user 'root'@'localhost' (using password yes)的問題

        買了新電腦,裝上MySQL建立連線後打不開,提示“1045 access denied for user 'root'@'localhost' (using password yes)”,我是吃瓜群眾一個,網上搜了好久,其實早就看到解決辦法了,但是由於自己水平

windows下忘記mysql密碼,登入進入mysql解決方案

1.stop mysql service net stop mysql 2,執行cmd,切換到mysql的bin目錄,執行命令 mysqld --defaults-file="C:\Program

第一篇部落格JavaScript錯誤繼續執行

1.問題:程式js遇見錯誤undefined,程式終止。 解決方案: try catch var ddd=$(div).highcharts(); try{ if (typeof(ddd.reflow()) !

分支覆蓋率測試用斷言錯誤的測試類測試結果

分支覆蓋率就是用junit寫測試類去測試寫好的原始碼,讓測試程式碼走進每一個if分支或者for迴圈的佔比。有時候原始碼需要連線資料庫或者需要正確的引數格式,而測試只要走進分支即可,不需要用真實資料(造資料浪費時間),可以用try--catch捕捉到異常,並使用斷言assert

SHELL指令碼mysql同步錯誤

mysql主從複製,經常會遇到錯誤而導致slave端複製中斷,這個時候一般就需要人工干預,跳過錯誤才能繼續 跳過錯誤有兩種方式: 1.跳過指定數量的事務: mysql>slave stop; my

Mac上Mysql密碼和許可權的方法

解決的主要錯誤為:經典的1045錯誤 ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password) 話不多說,上解決方案: (1)在系統偏好設定裡面找到mysql服務,直接關閉(

C#工作日,計算幾個工作日之後到期的方法

double helper == spa public data- return mes cal 需求:消費者投訴企業,企業在2個工作日之內做出應答。 分析:1.工作日要刨去周末和法定節假日,而且每年的節假日不一樣。 2.消費者可以在任意時間發起投訴,如果在非工作日發起

Mysql主從配置和事務

mysql主從配置和跳過事務Mysql主從配置和跳過事務一、介紹:大型網站中數據層還是原來那種傳統的數據架構,或者只是淡淡靠一臺服務器來扛,如此多的數據庫連接操作,數據必然會崩潰,數據丟失的話,可想而知後果不堪設想。所以我們想到很多解決方法·:一方面采用優秀的代碼框架,進行代碼的優化,采用優秀的數據緩存技術如

mysql開啟skip-name-resolve 導致[email protected](localhost)訪問引發的ERROR 1045 (28000)錯誤解決方案

its 遠程訪問 5.6 速度 base mat change http oracl 為什麽配置skip-name-resolve? 由於mysql -h${ip} 遠程訪問速度過慢, mysql -h172.16.66.171 -uroot -p123456 根據網