A slave with the same server_uuid as this slave has connected to the master

Got fatal error 1236 from master when reading data from binary log: 'A slave with the same server_uuid as this slave has connected to the master;

mysql version 5.6.28 
system version  rhel 6.7

    在用虛擬機配置mysql一主兩從的主從複製結構,發現當一臺從庫啓動複製的時候。另一臺的Slave_IO_Running: 就停止的奇怪現象

slave01> show slave status\G;
*************************** 1. row ***************************
               Slave_IO_State: 
                  Master_Host: 192.10.10.114
                  Master_User: rep
                  Master_Port: 3306
                Connect_Retry: 60
              Master_Log_File: mysql-bin.000009
          Read_Master_Log_Pos: 3353
               Relay_Log_File: slave01-relay-bin.000003
                Relay_Log_Pos: 1257
        Relay_Master_Log_File: mysql-bin.000009
             Slave_IO_Running: No
            Slave_SQL_Running: Yes
              Replicate_Do_DB: 
          Replicate_Ignore_DB: 
           Replicate_Do_Table: 
       Replicate_Ignore_Table: 
      Replicate_Wild_Do_Table: 
  Replicate_Wild_Ignore_Table:

slave02> show slave status\G;
*************************** 1. row ***************************
               Slave_IO_State: 
                  Master_Host: 192.10.10.115
                  Master_User: rep2
                  Master_Port: 3306
                Connect_Retry: 60
              Master_Log_File: mysql-bin.000009
          Read_Master_Log_Pos: 3353
               Relay_Log_File: slave01-relay-bin.000003
                Relay_Log_Pos: 1257
        Relay_Master_Log_File: mysql-bin.000009
             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:


    繼續檢查報錯,發現在有問題的slave上有以下報錯

Last_IO_Error: Got fatal error 1236 from master when reading data from binary log: 'A slave with the same server_uuid as this slave has connected to the master; the first event 'mysql-bin.000009' at 2379, the last event read from './mysql-bin.000009' at 3353, the last byte read from './mysql-bin.000009' at 3353.'

    報錯的大概意思是說,Slave的server_uuid 有衝突,導致一主多從的主從複製有問題,隨後登錄主庫檢查,發現只有一個slave server_uuid

master> show slave hosts;
+-----------+------+------+-----------+--------------------------------------+
| Server_id | Host | Port | Master_id | Slave_UUID                           |
+-----------+------+------+-----------+--------------------------------------+
|         3 |      | 3306 |         1 | 0f2ace9a-19d8-11e6-bb61-000c29e122c4 |
+-----------+------+------+-----------+--------------------------------------+

登錄分別登錄兩個從庫檢查auto.cnf,發現兩個slave節點的server_uuid一致,到此問題大概已經確認了,由於第二個slave節點是虛擬機複製過來的,因此mysql目錄下的auto.cnf也一起復制過來,導致兩個slave節點auto.cnf內容相同

[root@slave01 ~]# more /usr/local/mysql/data/auto.cnf
[auto]
server-uuid=0f2ace9a-19d8-11e6-bb61-000c29e122c4

[root@slave02 ~]# more /usr/local/mysql4/data/auto.cnf
[auto]
server-uuid=0f2ace9a-19d8-11e6-bb61-000c29e122c4

在對auto.cnf進行備份後,嘗試對其進行刪除,然後重新啓動mysql,
 MYSQL>start slave;

slave01> show slave status\G;
*************************** 1. row ***************************
               Slave_IO_State: Waiting for master to send event
                  Master_Host: 192.10.10.114
                  Master_User: rep
                  Master_Port: 3306
                Connect_Retry: 60
              Master_Log_File: mysql-bin.000010
          Read_Master_Log_Pos: 220
               Relay_Log_File: slave01-relay-bin.000006
                Relay_Log_Pos: 383
        Relay_Master_Log_File: mysql-bin.000010
             Slave_IO_Running: Yes
            Slave_SQL_Running: Yes
            
            
            
slave02> show slave status\G;
*************************** 1. row ***************************
               Slave_IO_State: Waiting for master to send event
                  Master_Host: 192.10.10.115
                  Master_User: rep2
                  Master_Port: 3306
                Connect_Retry: 60
              Master_Log_File: mysql-bin.000010
          Read_Master_Log_Pos: 220
               Relay_Log_File: slave02-relay-bin.000006
                Relay_Log_Pos: 383
        Relay_Master_Log_File: mysql-bin.000010
             Slave_IO_Running: Yes
            Slave_SQL_Running: Yes
                      
    重啓後兩個slave節點的複製都已經正常了,此時在主庫上進行查詢,兩個不同的slave的server_uuid已經輸出了

master> show slave hosts;
+-----------+------+------+-----------+--------------------------------------+
| Server_id | Host | Port | Master_id | Slave_UUID                           |
+-----------+------+------+-----------+--------------------------------------+
|         3 |      | 3306 |         1 | 7ca50dca-2125-11e6-ab00-000c29695898 |
|         2 |      | 3306 |         1 | 0f2ace9a-19d8-11e6-bb61-000c29e122c4 |
+-----------+------+------+-----------+--------------------------------------+

至此,故障解決到一個段落了。

那server_uuid是個啥東西?看下官方的解釋

#######什麼是 server_uuid
############################

從MySQL5.6開始,除了用戶提供的一個server-id之外,服務器還生成了一個真正的UUID,這個是可作爲全局,只讀的變量server_uuid。

該auto.cnf文件具有類似於my.cnf或my.ini文件的文件的格式。在MySQL5.6,auto.cnf只有一個[auto]條目,包含一個server_uuid的設置和值;

該文件的內容類似如下:

[auto]
server_uuid=8a94f357-aab4-11df-86ab-c80aa9429562


注意事項 

該auto.cnf文件是在mysql啓動後自動生成的;不必要嘗試寫入或修改此文件。

開使用MySQL 5.6複製的時候,master和slave知道彼此的的UUID。一個salve的UUID的值可以在SHOW SLAVE HOSTS的輸出中可以看出。一旦在從庫上START SLAVE已經執行,主庫的UUID的值可在SHOW SLAVE STATUS有效的輸出。


注意
執行STOP SLAVE或RESET SLAVE語句不重置在slave從庫上所用主庫的UUID。

在MySQL 5.6.5或更高版本,服務器的server_uuid也在GTIDs用於源自該服務器上的事務

從庫啓動時,,如果master的UUID等於其自身,Slave I/O線程產生一個錯誤並中止,除非設置--replicate-same-server-id選項。此外,如果任以下列條件爲真,slave I/O線程生成警告:


不存在具有預期server_uuid的master主庫。
master的server_uuid發生了變化,儘管沒有CHANGE MASTER TO語句曾經被執行。

注意

即使MySQL中5.6加入了 server_uuid系統變量,也不會改變對每個M準備和運行MySQL複製的節點設置唯一--server-id 的要求。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章