GTID复制失败错误1062

时间:2017-02-21 20:17:13

标签: mysql replication

我在设置从属复制时遇到问题。两者都使用mysql 5.6并启用GTID。 Master位于rackspace的云数据库HA实例

我包含的转储上有一个GTID和主。

我通过将以下内容添加到从属设备上来启用GTID(我没有打开它)。然后我删除了所有数据库,因此它很新鲜。

gtid_mode=ON
enforce_gtid_consistency=true
log_bin=/Library/Application Support/appsolute/MAMP PRO/db/mysql56/log
log_slave_updates=true
binlog_format=mixed

我跑的命令:

mysqldump  --tz-utc=false -u root -pPASSWORD --host=HOST --all-databases > dump.sql

mysql>CHANGE MASTER TO MASTER_HOST = 'MASTER_HOST', MASTER_PORT = 3306, MASTER_USER = 'repl_user', MASTER_PASSWORD = 'PASSWORD', MASTER_AUTO_POSITION = 1;
mysql>reset master;
mysql>source dump.sql;
mysql>start slave;


mysql> show slave status \G
*************************** 1. row ***************************
               Slave_IO_State: Waiting for master to send event
                  Master_Host: IP
                  Master_User: repl_user
                  Master_Port: 3307
                Connect_Retry: 60
              Master_Log_File: replica-2053073453-bin.000026
          Read_Master_Log_Pos: 1022001275
               Relay_Log_File: mysql-relay-bin.000002
                Relay_Log_Pos: 7600
        Relay_Master_Log_File: replica-2053073453-bin.000026
             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 '0db833be2a27f7fac7fa3ee1165256a398b7065f' for key 'PRIMARY'' on query. Default database: 'phppoint_demo2'. Query: 'INSERT INTO `phppos_sessions` (`id`, `ip_address`, `timestamp`, `data`) VALUES ('0db833be2a27f7fac7fa3ee1165256a398b7065f', 'IP', 1487705858, '')'
                 Skip_Counter: 0
          Exec_Master_Log_Pos: 1018575999
              Relay_Log_Space: 3433080
              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 '0db833be2a27f7fac7fa3ee1165256a398b7065f' for key 'PRIMARY'' on query. Default database: 'phppoint_demo2'. Query: 'INSERT INTO `phppos_sessions` (`id`, `ip_address`, `timestamp`, `data`) VALUES ('0db833be2a27f7fac7fa3ee1165256a398b7065f', 'IP', 1487705858, '')'
  Replicate_Ignore_Server_Ids: 
             Master_Server_Id: 2053073453
                  Master_UUID: 979f153e-2d80-11e6-bb91-00185119e861
             Master_Info_File: /Library/Application Support/appsolute/MAMP PRO/db/mysql56/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: 170221 14:55:55
               Master_SSL_Crl: 
           Master_SSL_Crlpath: 
           Retrieved_Gtid_Set: d2ce9c03-2d7f-11e6-bb8c-001851fe939d:10115103-10119980
            Executed_Gtid_Set: 979f153e-2d80-11e6-bb91-00185119e861:1-17,
d2ce9c03-2d7f-11e6-bb8c-001851fe939d:1-10115113
                Auto_Position: 1

我按照以下步骤操作:(如何以良好和缓慢的方式恢复奴隶)

https://www.percona.com/blog/2013/02/08/how-to-createrestore-a-slave-using-gtid-replication-in-mysql-5-6/

1 个答案:

答案 0 :(得分:0)

通常,这意味着主服务器和从服务器上的数据集不同。我们通常做的是使用xtrabackup创建二进制备份,将其传输到从属服务器,然后使用MASTER_AUTO_POSITION=1开始复制。在您的特定示例中, first 需要加载转储,然后执行CHANGE MASTER命令。

事实上,在与OP聊天后,他发现问题出在创建部分mysqldump,而不是转储所有信息。