1. 程式人生 > >mysql slave error處理

mysql slave error處理

備庫掛了:slave io/sql thread error

  • 0.關鍵點:

    1.show slave status\G; 檢視掛了的原因
    2.一般處理完後要tcp校驗一下
    3.如果是宕機或者例項重啟,在主庫執行start slave前要在備庫上看看有沒有回滾程序ps aux | grep magiclog ,如果有 magiclog 程序在執行說明在回滾。回滾過程中不能執行start slave,不然會報各種slave err

  • 1.報錯:檔案中位點>檔案大小
    Got fatal error 1236 from master when reading data from binary log: 'Client requested master to start replication from position > file size; the first event 'mysql-bin.000020' at 307263712, the last event read from '/u01/my3308/log/mysql-bin.000020' at 4, the last byte read from '/u01/my3308/log/mysql-bin.000020' at 4.'

    解決:重指位點 //MASTER_LOG_FILE為當前備份Relay_Master_Log_File的下一個,MASTER_LOG_POS=4
    stop slave ;
    CHANGE MASTER TO MASTER_LOG_FILE=’mysql-bin.016729’, MASTER_LOG_POS=4;
    start slave;
    select sleep(0.1);
    show slave status\G;

  • 2.沒有報錯資訊,只是顯示 Slave_IO_Running: No Slave_SQL_Running: No

    用start slave;啟動時報錯如下
    1.Could not initialize master info structure; more error messages can be found in the MySQL error log
    看/u02/my3308/log/alert.log日誌,發現錯誤如下
    [ERROR] Error looking for file after /u01/my3308/log/relaylog.000064.
    仔細看位點會發現很奇怪的事情
    Read_Master_Log_Pos: 95926035
    Exec_Master_Log_Pos: 95969857
    執行位點比讀master的位點還大了

    解決:沒辦法,只能reset然後重指位點了 記錄好Relay_Master_Log_File: 和 Exec_Master_Log_Pos:
    reset slave;
    CHANGE MASTER TO MASTER_LOG_FILE=’mysql-bin.001458’, MASTER_LOG_POS=266387470;
    start slave;
    select sleep(0.1);
    show slave status\G;

  • 3.Slave failed to initialize relay log info structure from the repository
    解決:同樣的處理方法

  • 4.如下錯誤
    Worker 15 failed executing transaction '' at master log mysql-bin.000012, end_log_pos 468767971; Could not execute Write_rows_v1 event on table cbu_nebulabody_00.short_url_0011; Duplicate entry '5730576' for key 'PRIMARY', Error_code: 1062; handler error HA_ERR_FOUND_DUPP_KEY; the event's master log FIRST, end_log_pos 468767971
    或者
    Last_SQL_Errno: 1032
    Could not execute Update_rows event on table cbu_vaseq7.vas_eq_enquiries_0102; Can't find record in 'vas_eq_enquiries_0102', Error_code: 1032; handler error HA_ERR_KEY_NOT_FOUND; the event's master log
    mysql-bin.000417, end_log_pos 44444276, Error_code: 1032
    或者
    Cannot execute the current event group in the parallel mode. Encountered event Xid, relay-log name /u01/my3318/log/relaylog.000030, position 372 which prevents execution of this event group in parallel mode. Reason: the event is a part of a group that is unsupported in the parallel execution mode.

解決:直接跳過:sql_slave_skip_counter=1是指跳過一個事務的意思
stop slave;set global sql_slave_skip_counter=1;start slave;select sleep(0.1);show slave status\G;

  • 5.其他報錯,可以選擇跳過錯誤
    show slave status\G;
    show variables like ‘%slave_parallel_workers’;
    set global slave_parallel_workers = 0;
    set global slave_exec_mode = smart;
    start slave;
    select sleep(0.1);
    show slave status\G;
    stop slave;
    set global slave_exec_mode = strict;
    set global slave_parallel_workers = 16;
    start slave;
    select sleep(0.1);
    show slave status\G;

  • 6.GTID報錯