Linux

mysql replication last error

Naan 2014. 2. 19. 10:54
반응형

mysql replication last error 간혹 발생이 된다.



mysql> show slave status\G

*************************** 1. row ***************************

               Slave_IO_State: Waiting for master to send event

                  Master_Host: 192.168.0.2

                  Master_User: backup

                  Master_Port: 3306

                Connect_Retry: 60

              Master_Log_File: mysql-bin.000001

          Read_Master_Log_Pos: 456557

               Relay_Log_File: mysqld-relay-bin.000005

                Relay_Log_Pos: 297844

        Relay_Master_Log_File: mysql-bin.000001

             Slave_IO_Running: Yes

            Slave_SQL_Running: No

              Replicate_Do_DB:

          Replicate_Ignore_DB:

           Replicate_Do_Table:

       Replicate_Ignore_Table:

      Replicate_Wild_Do_Table:

  Replicate_Wild_Ignore_Table:

                   Last_Errno: 1062

                   Last_Error: Error 'Duplicate entry '810990' for key 'PRIMARY'                                                                                                                                                                                                                                             ' on query. Default database: 'jiradb'. Query: 'INSERT INTO cwd_user_attributes                                                                                                                                                                                                                                              (ID, user_id, directory_id, attribute_name, attribute_value, lower_attribute_val                                                                                                                                                                                                                                             ue) VALUES (810990, 12275, 1, 'login.currentFailedCount', '0', '0')'

                 Skip_Counter: 0

          Exec_Master_Log_Pos: 347080

              Relay_Log_Space: 423441

              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: 1062

               Last_SQL_Error: Error 'Duplicate entry '810990' for key 'PRIMARY'                                                                                                                                                                                                                                             ' on query. Default database: 'jiradb'. Query: 'INSERT INTO cwd_user_attributes                                                                                                                                                                                                                                              (ID, user_id, directory_id, attribute_name, attribute_value, lower_attribute_val                                                                                                                                                                                                                                             ue) VALUES (810990, 12275, 1, 'login.currentFailedCount', '0', '0')'

1 row in set (0.00 sec)


위와 같이 특정 db때문에 에러가 발생하는경우가 생긴다.

그렇다면 아래와 같이 해주자  (slave 서버에서)


mysql> stopt slave;

Query OK, 0 rows affected (0.00 sec)


mysql> SET GLOBAL SQL_SLAVE_SKIP_COUNTER = 1;

Query OK, 0 rows affected (0.00 sec)


그리고 master 에 접속 정보를 다시 입력해주자

CHANGE MASTER TO MASTER_HOST='192.168.0.247', MASTER_USER='backup', MASTER_PORT=3306, MASTER_PASSWORD='123qwe', MASTER_LOG_FILE='mysql-bin.000004';


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.0.2

                  Master_User: backup

                  Master_Port: 3306

                Connect_Retry: 60

              Master_Log_File: mysql-bin.000001

          Read_Master_Log_Pos: 994861

               Relay_Log_File: mysqld-relay-bin.000002

                Relay_Log_Pos: 3996

        Relay_Master_Log_File: mysql-bin.000001

             Slave_IO_Running: Yes

            Slave_SQL_Running: Yes

              Replicate_Do_DB:

          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: 994861

              Relay_Log_Space: 4152

              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:

1 row in set (0.00 sec)


에러가 없어진것을 확인 할수 있다.


만약에 주기적으로 Last_SQL_Errno: 1062 발생한다면 무시 설정을 해주자


# vi /etc/my.conf

slave-skip-errors = 1062

추가 해주면 된다. 만약 에러코드가 1063번도 생긴다면 

slave-skip-errors = 1062, 1063 이런식으로 추가 해주면 된다.

반응형