MySQL 복제 · 3 min read · Nov 02, 2025
MySQL 복제 수리 방법

MySQL 복제를 설정했다면, 아마도 이 문제를 알고 있을 것입니다: 때때로 잘못된 MySQL 쿼리가 발생하여 복제가 더 이상 작동하지 않게 됩니다. 이 짧은 가이드에서는 MySQL 슬레이브에서 복제를 수리하는 방법을 설명합니다. 처음부터 다시 설정할 필요는 없습니다. 이 가이드는 MySQL 및 MariaDB를 위한 것입니다.
1 문제 식별하기
복제가 작동하는지 여부와 중단된 원인을 알아내기 위해 로그를 확인할 수 있습니다. 예를 들어, Debian에서는 MySQL 로그가 /var/log/syslog에 기록됩니다:
grep mysql /var/log/syslogserver1:/home/admin# grep mysql /var/log/syslog
MAR 19 09:56:08 http2 mysqld[1380]: 080529 9:56:08 [ERROR] Slave: Error 'Table 'mydb.taggregate_temp_1212047760' doesn't exist' on query. Default database: 'mydb'. Query: 'UPDATE thread AS thread,taggregate_temp_1212047760 AS aggregate
MAR 19 09:56:08 http2 mysqld[1380]: ^ISET thread.views = thread.views + aggregate.views
MAR 19 09:56:08 http2 mysqld[1380]: ^IWHERE thread.threadid = aggregate.threadid', Error_code: 1146
MAR 19 09:56:08 http2 mysqld[1380]: 080529 9:56:08 [ERROR] Error running query, slave SQL thread aborted. Fix the problem, and restart the slave SQL thread with "SLAVE START". We stopped at log 'mysql-bin.001079' position 203015142
server1:/home/admin#어떤 쿼리가 오류를 발생시켰는지, 그리고 복제가 중단된 로그 위치를 확인할 수 있습니다.
복제가 실제로 작동하지 않는지 확인하려면 MySQL에 로그인합니다:
mysql -u root -pMySQL 셸에서 다음을 실행합니다:
mysql> SHOW SLAVE STATUS \G만약 Slave_IO_Running 또는 Slave_SQL_Running 중 하나가 No로 설정되어 있다면, 복제가 중단된 것입니다:
mysql> SHOW SLAVE STATUS \G
************************* 1. row ***********************
Slave_IO_State: Waiting for master to send event
Master_Host: 1.2.3.4
Master_User: slave_user
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: mysql-bin.001079
Read_Master_Log_Pos: 269214454
Relay_Log_File: slave-relay.000130
Relay_Log_Pos: 100125935
Relay_Master_Log_File: mysql-bin.001079
Slave_IO_Running: Yes
Slave_SQL_Running: No
Replicate_Do_DB: mydb
Replicate_Ignore_DB:
Replicate_Do_Table:
Replicate_Ignore_Table:
Replicate_Wild_Do_Table:
Replicate_Wild_Ignore_Table:
Last_Errno: 1146
Last_Error: Error 'Table 'mydb.taggregate_temp_1212047760' doesn't exist' on query. Default database: 'mydb'.
Query: 'UPDATE thread AS thread,taggregate_temp_1212047760 AS aggregate
SET thread.views = thread.views + aggregate.views
WHERE thread.threadid = aggregate.threadid'
Skip_Counter: 0
Exec_Master_Log_Pos: 203015142
Relay_Log_Space: 166325247
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
1 row in set (0.00 sec)
mysql>2 MySQL 복제 수리하기
확실히 하기 위해 슬레이브를 중지합니다:
mysql> STOP SLAVE;문제를 해결하는 것은 실제로 매우 쉽습니다. 우리는 슬레이브에게 잘못된 SQL 쿼리를 단순히 건너뛰라고 지시합니다:
mysql> SET GLOBAL SQL_SLAVE_SKIP_COUNTER = 1;이것은 슬레이브에게 하나의 쿼리(복제를 중단시킨 잘못된 쿼리)를 건너뛰라고 지시합니다. 두 개의 쿼리를 건너뛰고 싶다면 대신 SET GLOBAL SQL_SLAVE_SKIP_COUNTER = 2;를 사용하면 됩니다.
그게 전부입니다. 이제 슬레이브를 다시 시작할 수 있습니다…
mysql> START SLAVE;… 그리고 복제가 다시 작동하는지 확인합니다:
mysql> SHOW SLAVE STATUS \Gmysql> SHOW SLAVE STATUS \G*********************** 1. row ************************* Slave_IO_State: Waiting for master to send event Master_Host: 1.2.3.4 Master_User: slave_user Master_Port: 3306 Connect_Retry: 60 Master_Log_File: mysql-bin.001079 Read_Master_Log_Pos: 447560366 Relay_Log_File: slave-relay.000130 Relay_Log_Pos: 225644062 Relay_Master_Log_File: mysql-bin.001079 Slave_IO_Running: Yes Slave_SQL_Running: Yes Replicate_Do_DB: mydb Replicate_Ignore_DB: Replicate_Do_Table: Replicate_Ignore_Table: Replicate_Wild_Do_Table: Replicate_Wild_Ignore_Table: Last_Errno: 0 Last_Error: Skip_Counter: 0 Exec_Master_Log_Pos: 447560366 Relay_Log_Space: 225644062 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: 0 1 row in set (0.00 sec) mysql>
보시다시피, 이제 Slave_IO_Running과 Slave_SQL_Running 모두 Yes로 설정되어 있습니다.
이제 MySQL 셸을 종료합니다…
mysql> quit;… 그리고 로그를 다시 확인합니다:
grep mysql /var/log/syslogserver1:/home/admin# grep mysql /var/log/syslog
MAR 19 09:56:08 http2 mysqld[1380]: 080529 9:56:08 [ERROR] Slave: Error 'Table 'mydb.taggregate_temp_1212047760' doesn't exist' on query. Default database: 'mydb'. Query: 'UPDATE thread AS thread,taggregate_temp_1212047760 AS aggregate
MAR 19 09:56:08 http2 mysqld[1380]: ^ISET thread.views = thread.views + aggregate.views
MAR 19 09:56:08 http2 mysqld[1380]: ^IWHERE thread.threadid = aggregate.threadid', Error_code: 1146
MAR 19 09:56:08 http2 mysqld[1380]: 080529 9:56:08 [ERROR] Error running query, slave SQL thread aborted. Fix the problem, and restart the slave SQL thread with "SLAVE START". We stopped at log 'mysql-bin.001079' position 203015142
MAR 19 11:42:13 http2 mysqld[1380]: 080529 11:42:13 [Note] Slave SQL thread initialized, starting replication in log 'mysql-bin.001079' at position 203015142, relay log '/var/lib/mysql/slave-relay.000130' position: 100125935
server1:/home/admin#마지막 줄은 복제가 다시 시작되었다고 말하며, 그 줄 이후에 오류가 없으면 모든 것이 정상입니다.
3 링크
- MySQL: http://www.mysql.com
새 게시물을 받은 편지함에서 받기
스팸은 없습니다. 언제든지 구독 해지 가능합니다.