[MySQL] mysql에서 replication error 처리

[MySQL] mysql에서 replication error 처리 updated_at: 2024-01-29 16:43

mysql에서 replication error 처리

본 문서는 예전 문서이므로 단지 참조로만 활용해 주세요.
시간이 되면 최근 것으로 업데이트 해 두겠습니다.

  • mysql replication 진행도중 slave서버의 error-log 파일내용을 확인한 후 대처법

계속적인 slave의 status를 감시한다.

show slave status \G

에러유형 1

  • [에러메시지]
100503 8:41:05 [ERROR] Error reading packet from server: log event entry exceeded
max_allowed_packet; Increase max_allowed_packet on master ( server_errno=1236)
100503 8:41:05
[ERROR] Got fatal error 1236: 'log event entry exceeded max_allowed_packet; Increase
max_allowed_packet on master' from master when reading data from binary log
100503 8:41:05 [Note]
Slave I/O thread exiting, read up to log 'binlog.021419', position 196980
  • [원인] : master서버의 max_allowed_packet 값이 작을 경우 문제가 발생할수 있다.
  • [대처법 1]
    • my.cnf파일을 수정해 준후 데몬을 재시작한다.
    • 데몬 재시작이 힘들경우 쉘 상에서 값을 변경한다.
mysql> SET GLOBAL max_allowed_packet = 1024*1024*100;
mysql> SET SESSION max_allowed_packet = 1024*1024*100;
  • [대처법 1] : master서버의 max_allowed_packet값이 충분히 큰데 위와 같은 오류가 발생할 경우..
  • 먼저 master서버의 binlog파일을 확인해본다.
[root@db11 slave_log]#mysqlbinlog binlog.021419 | more
..........
# at 196800
#100503 7:16:31 server id 1 end_log_pos 196827
Xid = 3282913394
COMMIT/*!*/;
# at 196827
#100503 7:16:31 server id 1 end_log_pos
138 Query thread_id=235254463 exec_time=0 error_code=0
SET TIMESTAMP=1272838591/*!*/;
Update tablename Set count0/*!*/;
# at 196965
#100503
7:16:31 server id 1 end_log_pos 196992 Xid = 3282913395
COMMIT/*!*/;
# at 196992
#100503 7:16:31 server id 1 end_log_pos 133 Query thread_id=232937265 exec_time=0
error_code=0
SET TIMESTAMP=1272838591/*!*/;
Update tablename Set size = 295976960/*!*/;
# at 197125
                    
  • 확인 결과 196980 위치가 존재하지 않는다.
  • master_log_pos를 다음값으로 변경하면 끝.
mysql> stop slave;
mysql> change master to master_log_pos = 196992;
mysql> start slave;

에러유형 2

  • [에러메시지]
100130 12:57:07 [ERROR] Slave: Error ''SQL 구문에 오류가 있습니다.' 에러 같읍니다. ('' 명령어 라인 1)' on query.
Default database: 'dbname'. Query: 'UPDATE PARTNER_CNT SET .... WHERE ...', Error_code: 1064
100130 12:57:07 [ERROR] Error running query, slave SQL thread aborted. Fix the problem,
and restart the slave SQL thread with "SLAVE START". We stopped at log 'binlog.007704' position 70234030
  • [원인] :

키값이 중복되어 슬레이브에서 쿼리가 실행되지 못하고 있는것이다.
정상적인 리플리케이션에서는 문제가 없지만 갑작스런 서버 다운, 네트워크 단절이 발생했을 경우 위와 같은 오류가 발생한다.
아래 명령을 입력하여 해결 할 수 있다.

  • [대처법] :
mysql> stop slave;
mysql> SET GLOBAL SQL_SLAVE_SKIP_COUNTER=1;
mysql> start slave; 

에러유형 3

  • [에러메시지]
100122 0:22:44 [ERROR] Error reading packet from server: Lost connection to MySQL server during query ( server_errno=2013)
100122 0:22:44 [Note] Slave I/O thread: Failed reading log event,
reconnecting to retry, log 'binlog.017528' position 90025355
100122 0:22:48 [Note] Slave:
connected to master 'xxxxxx@아이피',replication resumed in log
'binlog.017528' at position 90025355
  • [원인] :

master서버와의 연결이 끊어지면 위와 같은 오류 메세지를 출력하고 리플리케이션이 중지된다.br> master서버가 정상적으로 돌아왔다면 slave 서버에 mysql을 접속한후 아래 명령을 입력한다.

  • [대처법] :
mysql> stop slave;
mysql> start slave;

에러유형 4

  • [에러메시지]
100122 1:35:56 [Note] Slave I/O thread killed while reading event
100122 1:35:56 [Note] Slave I/O thread exiting, read up to log 'binlog.017530',
position 33231841
100122 1:36:05 [Note] Slave SQL thread initialized, starting
replication in log 'binlog.017528' at position 195, relay log 
'/db/slave_log/relay_log.002684' position: 90005865
100122 1:36:05 [ERROR] Error
in Log_event::read_log_event(): 'Event too big', data_len: 811157539, event_type:0
100122 1:36:05 [ERROR] Error reading relay log event: slave SQL thread aborted
because of I/O error
100122 1:36:05 [ERROR] Slave: Could not parse relay log
event entry. The possible reasons are: the master's binary log is corrupted (you can
check this by running 'mysqlbinlog' on the binary log), the slave's relay log is
corrupted (you can check this by running 'mysqlbinlog' on the relay log), a network
problem, or a bug in the master's or slave's MySQL code. If you want to check the
master's binary log or slave's relay log, you will be able to know their names by
issuing 'SHOW SLAVE STATUS' on this slave. Error_code: 0
100122 1:36:05 [ERROR]
Error running query, slave SQL thread aborted. Fix the problem, and restart the
slave SQL thread with "SLAVE START". We stopped at log 'binlog.017528' position 195
100122 1:36:05 [Note] Slave I/O thread: connected to master xxxx@아이피,
replication started in log 'binlog.017530' at position 33231841

  • [원인] :

slave서버가 갑작스럽게 다운 되었을때 로그 파일이 깨져서 위와 같은 오류가 발생한다.
위 에러로그에서는 relay_log.002684 로그에서 중지 되었다.
slave_log가 쌓이는 디렉토리( /db/slave_log/)에 relay_log.002685 파일이 있는지 확인후 아래 명령을 입력한다.

  • [대처법] :
mysql> stop slave;
mysql> CHANGE MASTER TO
relay_log_file='/db/slave_log/relay_log.002685', relay_log_pos=0;
mysql> start slave;
평점을 남겨주세요
평점 : 5.0
총 투표수 : 1