简体   繁体   中英

GTID replication failing error 1062

I am having trouble setting up a slave replication. Both use mysql 5.6 and have GTID on. Master is on rackspace's cloud databases HA instance

The dump I include has a GTID on it and the master.

I enabled GTID on slave by adding the following to the slave (i didn't have it on). I then deleted all the databases so it was fresh.

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

Commands I ran:

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

I followed steps at: (How to restore a slave in a good and slow way)

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

Typically it means that the dataset on master and slave is different. What we normally do is create a binary backup with xtrabackup , transfer that to a slave, then start replication with MASTER_AUTO_POSITION=1 . In your particular example you first need to load the dump and then execute the CHANGE MASTER command.

In fact, after a chat with the OP he figured out that the problem was in creating a partial mysqldump, rather than dumping all of the information.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM