同一行ID后,主主机复制失败

时间:2015-01-27 11:44:05

标签: mysql linux database replication database-replication

您好我已经设置了Master - Master mysql复制。

Master A = Localsystem
Master B = Server

工作正常。 但是当A大师从B大师无法到达时

我复制的表有Id字段直到 - 233

现在在同一个表中的两个主服务器上都插入了一行。

表中都有下一个ID 234。

当A大师成为B大师可以到达的时候 两端的复制都失败了。

**

on Master A;
show master status \G;

**

*************************** 1. row ***************************
               Slave_IO_State: Waiting for master to send event
                  Master_Host: 13.235.146.234
                  Master_User: replica
                  Master_Port: 3306
                Connect_Retry: 60
              Master_Log_File: mysql-bin.000097
          Read_Master_Log_Pos: 33310336
               Relay_Log_File: ded18908-1-relay-bin.000003
                Relay_Log_Pos: 4445481
        Relay_Master_Log_File: mysql-bin.000097
             Slave_IO_Running: Yes
            Slave_SQL_Running: No
              Replicate_Do_DB: 
          Replicate_Ignore_DB: 
           Replicate_Do_Table: school_testing.ai_student_attendance,school_testing.ai_staff_attendance
       Replicate_Ignore_Table: 
      Replicate_Wild_Do_Table: 
  Replicate_Wild_Ignore_Table: 
                   Last_Errno: 1062
                   Last_Error: Error 'Duplicate entry '234' for key 'PRIMARY'' on query. Default database: 'school_testing'. Query: 'INSERT INTO `school_testing`.`ai_student_attendance` (`ids`, `student_id`, `atten_list`, `atten_cont`, `month`) VALUES (NULL, '124', 'sasas', 'sasas', 'sasas')'
                 Skip_Counter: 0
          Exec_Master_Log_Pos: 20766001
              Relay_Log_Space: 22735128
              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 '234' for key 'PRIMARY'' on query. Default database: 'school_testing'. Query: 'INSERT INTO `school_testing`.`ai_student_attendance` (`ids`, `student_id`, `atten_list`, `atten_cont`, `month`) VALUES (NULL, '124', 'sasas', 'sasas', 'sasas')'
  Replicate_Ignore_Server_Ids: 
             Master_Server_Id: 3
1 row in set (0.00 sec)

ERROR: 
No query specified

**

Master - B 
show slave status \G;

**

*************************** 1. row ***************************
               Slave_IO_State: Waiting for master to send event
                  Master_Host: 182.21.11.142
                  Master_User: replica
                  Master_Port: 22331
                Connect_Retry: 60
              Master_Log_File: mysql-bin.000003
          Read_Master_Log_Pos: 111212
               Relay_Log_File: mysqld-relay-bin.000002
                Relay_Log_Pos: 43815
        Relay_Master_Log_File: mysql-bin.000003
             Slave_IO_Running: Yes
            Slave_SQL_Running: No
              Replicate_Do_DB: 
          Replicate_Ignore_DB: 
           Replicate_Do_Table: school_testing.ai_student_attendance,school_testing.ai_staff_attendance
       Replicate_Ignore_Table: 
      Replicate_Wild_Do_Table: 
  Replicate_Wild_Ignore_Table: 
                   Last_Errno: 1062
                   Last_Error: Error 'Duplicate entry '234' for key 'PRIMARY'' on query. Default database: 'school_testing'. Query: 'INSERT INTO `school_testing`.`ai_student_attendance` (`ids`, `student_id`, `atten_list`, `atten_cont`, `month`) VALUES (NULL, '125', 'dsdsdsa', 'dsada', 'asdasdadasdadada')'
                 Skip_Counter: 0
          Exec_Master_Log_Pos: 83284
              Relay_Log_Space: 72201
              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 '234' for key 'PRIMARY'' on query. Default database: 'school_testing'. Query: 'INSERT INTO `school_testing`.`ai_student_attendance` (`ids`, `student_id`, `atten_list`, `atten_cont`, `month`) VALUES (NULL, '125', 'dsdsdsa', 'dsada', 'asdasdadasdadada')'
1 row in set (0.00 sec)

ERROR: 
No query specified

我不知道如何纠正这个问题。我需要专家帮助。

这是一种罕见的情况。但是当我面对这个问题时,我的复制失败了

1 个答案:

答案 0 :(得分:1)

您需要做的是在每个母版上使用不同的ID偏移:

你的my.cnf文件中的

-

在Master 1上:

auto_increment_increment=2 
auto_increment_offset=1 

在Master 2上:

auto_increment_increment=2 
auto_increment_offset=2 

以便每个人生成一组不同的id。

e.g。

Master 1 = 1,3,5

大师2 = 2,4,6

通过这种方式,您不应该出现重复的输入错误(只要您使用auto_increment作为您的ID),而不是手动输入它们。