2017-02-21 62 views
0

我在設置從屬複製時遇到問題。兩者都使用mysql 5.6並啓用GTID。主站位於機架空間的雲數據庫HA實例GTID複製失敗錯誤1062

我包含的轉儲在它和主站上有一個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/

回答

0

通常這意味着主站和從站的數據集不同。我們通常所做的就是創建一個xtrabackup的二進制備份,將其轉移到從屬設備,然後使用MASTER_AUTO_POSITION=1開始複製。在你的具體例子中你需要第一個加載轉儲,然後然後執行CHANGE MASTER命令。

事實上,在與OP交談後,他發現問題在於創建了部分mysqldump,而不是傾銷所有的信息。

+0

我重複了這個過程,通過改變順序並導致相同的錯誤。備份被採取並立即加載到奴隸,所以它沒有太大的不同 –

+0

您的轉儲包含'SET @@ GLOBAL.GTID_PURGED ='?另外,由於您正在設置一個新的奴隸,我只需按照該文章的頂部。 :) – favoretti

+0

是的,它包含它('SET @@ GLOBAL.GTID_PURGED ='979f153e-2d80-11e6-bb91-00185119e861:1-17, d2ce9c03-2d7f-11e6-bb8c-001851fe939d:1-10133617';)' 。由於錯誤'GTID_PURGED只能在GTID_EXECUTED爲空時才能設置,所以我無法完成最上面的部分。「所以我想到了文章的底部部分。 –