Mysql 主從常遇問題

1、1032錯誤

此問題很常見,大多是由於主從延遲,例如主中的新增和刪除操作連續同步到從庫,但是從庫的刪除先進行了,那麼此時就會報1032錯誤.常見的錯誤消息內容(來自https://www.cnblogs.com/langdashu/p/5920436.html)如下:

Slave_SQL_Running: NOLast_SQL_Errno: 1032
Last_SQL_Error: Worker 3 failed executing transaction '' at master log mysql-bin.000003, end_log_pos 440267874;
          Could not execute Delete_rows event on table db_test.tbuservcbgolog; Can't find record in 'tbuservcbgolog', Error_code: 1032;
          handler error HA_ERR_KEY_NOT_FOUND; the event's master log mysql-bin.000003, end_log_pos 440267874

windows下的一種解決方式如下:

首先定位到mysqlbinlog.exe的運行目錄,接着打開cmd執行以下語句

mysqlbinlog.exe --base64-output=decode-rows -vv "binlog文件的全路徑" --stop-position=111(1032輸出的錯誤消息中的end_log_pos) >11.txt(解析後的可讀binlog文件生成路徑)

11.txt文件生成後,打開git bash執行以下命令

grep -i -50 "1032輸出的錯誤消息中的end_log_pos" 11.txt

查找具體的錯誤執行語句,結果大致如下:

### DELETE FROM `庫`.`表`
### WHERE
### @1='812d198d-f1f5-4b12-9542-35b23aed0040' /* VARSTRING(144) meta=144 nullable=0 is_null=0 */
### @2='ae67acb3-93b2-4c7b-830d-9dd38c962ba1' /* VARSTRING(144) meta=144 nullable=1 is_null=0 */
### @3='c39ff2f5-ce7d-44c5-ad79-3d0c88fb82c7' /* VARSTRING(144) meta=144 nullable=1 is_null=0 */

接着根據delete語句反向insert數據,重啓slave.

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章