마스터 서버에 무리가 갈 것 같아서 Slave 서버에서 하나씩 커넥션 돌려 가면서 인덱스 작업을 먼저 하고,
제일 마지막에 master서버에서 인덱스 작업을 해 주게 되면…
그 순간 동일 이름의 오브젝트가 Slave 서버에 있는 상태가 되므로, 리플리케이션 에러가 발생 함.
mysql> show slave status\G *************************** 1. row *************************** Slave_IO_State: Waiting for master to send event Master_Host: 192.168.187.129 Master_User: replicator Master_Port: 3306 Connect_Retry: 60 Master_Log_File: bin.000013 Read_Master_Log_Pos: 688111235 Relay_Log_File: relay.004538 Relay_Log_Pos: 688082757 Relay_Master_Log_File: bin.000013 Slave_IO_Running: Yes Slave_SQL_Running: No Replicate_Do_DB: Replicate_Ignore_DB: mysql Replicate_Do_Table: Replicate_Ignore_Table: Replicate_Wild_Do_Table: Replicate_Wild_Ignore_Table: Last_Errno: 1061 Last_Error: Error 'Duplicate key name 'oauth_users_name_domain'' on query. Default database: 'cyauth'. Query: 'create index oauth_users_name_domain on oauth_users( username , domain , userid )' Skip_Counter: 0 Exec_Master_Log_Pos: 688082604 Relay_Log_Space: 688111896 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 'oauth_users_name_domain'' on query. Default database: 'cyauth'. Query: 'create index oauth_users_name_domain on oauth_users( username , domain , userid )' Replicate_Ignore_Server_Ids: Master_Server_Id: 1 Master_UUID: 2dabcf42-b0bc-11e3-8352-00259008cf3e Master_Info_File: /data/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: 170126 15:22:23 Master_SSL_Crl: Master_SSL_Crlpath: Retrieved_Gtid_Set: Executed_Gtid_Set: Auto_Position: 0
에러파일로그 파일 내용 :
2017-01-26 15:22:23 9983 [ERROR] Slave SQL: Error 'Duplicate key name 'oauth_users_name_domain'' on query. Default database: 'cyauth'. Query: 'create index oauth_users_name_domain on oauth_users( username , domain , userid )', Error_code: 1061 2017-01-26 15:22:23 9983 [Warning] Slave: Duplicate key name 'oauth_users_name_domain' Error_code: 1061 2017-01-26 15:22:23 9983 [ERROR] Error running query, slave SQL thread aborted. Fix the problem, and restart the slave SQL thread with "SLAVE START". We stopped at log 'bin.000013' position 688082604 |
그럴 경우 Skip Duplicate 해주기 위하여 다음과 같은 작업을 해 주면 된다.
mysql> stop slave ;
mysql> SET GLOBAL SQL_SLAVE_SKIP_COUNTER=1; --> 여기선 중복 에러 나는 것이 1개 이므로, 여러 개 일 경우 숫자를 크게 SET GLOBAL SQL_SLAVE_SKIP_COUNTER=100 ;
또는 위에 에러 번호가 1061 이였으므로, my.cnf 파일에 다음과 같이 설정 가능 my.cnf slave-skip-errors = 1061,1062,1063 등등 스킵하고 싶은 에러번호 나열
mysql> start slave ; Query OK, 0 rows affected (0.00 sec)
mysql> show slave status\G *************************** 1. row *************************** Slave_IO_State: Waiting for master to send event Master_Host: 192.168.187.129 Master_User: replicator Master_Port: 3306 Connect_Retry: 60 Master_Log_File: bin.000013 Read_Master_Log_Pos: 688143729 Relay_Log_File: relay.004540 Relay_Log_Pos: 27101 Relay_Master_Log_File: bin.000013 Slave_IO_Running: Yes Slave_SQL_Running: Yes Replicate_Do_DB: Replicate_Ignore_DB: mysql 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: 688143729 Relay_Log_Space: 42539 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 Master_SSL_Verify_Server_Cert: No Last_IO_Errno: 0 Last_IO_Error: Last_SQL_Errno: 0 Last_SQL_Error: Replicate_Ignore_Server_Ids: Master_Server_Id: 1 Master_UUID: 2dabcf42-b0bc-11e3-8352-00259008cf3e Master_Info_File: /data/master.info SQL_Delay: 0 SQL_Remaining_Delay: NULL Slave_SQL_Running_State: Slave has read all relay log; waiting for the slave I/O thread to update it Master_Retry_Count: 86400 Master_Bind: Last_IO_Error_Timestamp: Last_SQL_Error_Timestamp: Master_SSL_Crl: Master_SSL_Crlpath: Retrieved_Gtid_Set: Executed_Gtid_Set: Auto_Position: 0 |