mysql show slave 與 從庫複製新的從庫

細說show slave status參數詳解(最全)

本文出自 「鄭小明的技術博客」 博客,請務必保留此出處http://zhengmingjing.blog.51cto.com/1587142/1910565mysql

在搭建好mysql主從以後,咱們通常在從庫上經過命令sql

show slave status\G

 

 來查看主從的狀態,會有不少的參數,接下來筆者就帶你們好好的瞭解這些參數服務器

 

複製代碼
root@localhost (none)>show slave status\G
*************************** 1. row *************************** Slave_IO_State: Waiting for master to send event Master_Host: 192.168.1.100 Master_User: mysync Master_Port: 3306 Connect_Retry: 60 Master_Log_File: mysql-bin.001822 Read_Master_Log_Pos: 290072815 Relay_Log_File: mysqld-relay-bin.005201 Relay_Log_Pos: 256529594 Relay_Master_Log_File: mysql-bin.001821 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: Last_Errno: 0 Last_Error: Skip_Counter: 0 Exec_Master_Log_Pos: 256529431 Relay_Log_Space: 709504534 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: 2923 Master_SSL_Verify_Server_Cert: No Last_IO_Errno: 0 Last_IO_Error: Last_SQL_Errno: 0 Last_SQL_Error: Replicate_Ignore_Server_Ids: Master_Server_Id: 1 Master_UUID: 13ee75bb-99e2-11e6-be4d-b499baa80e6e Master_Info_File: /home/data/mysql/master.info SQL_Delay: 0 SQL_Remaining_Delay: NULL Slave_SQL_Running_State: Reading event from the relay log Master_Retry_Count: 86400 Master_Bind: Last_IO_Error_Timestamp: Last_SQL_Error_Timestamp: Master_SSL_Crl: Master_SSL_Crlpath: Retrieved_Gtid_Set: Executed_Gtid_Set: Auto_Position: 0 1 row in set (0.02 sec)
複製代碼

 

參數詳解:網絡

 

1. Slave_IO_Statepost

這裏顯示了當前slave I/O線程的狀態(slave鏈接到master的狀態)。狀態信息和使用show processlist | grep "system user"(會顯示兩條信息,一條slave I/O線程的,一條是slave SQL線程的)顯示的內容同樣。加密

 

slave I/O線程的狀態,有如下幾種:spa

       1) waiting for master update線程

           這是connecting to master狀態以前的狀態日誌

       2) connecting to mastercode

          I/O線程正嘗試鏈接到master

       3) checking master version

          在與master創建鏈接後,會出現該狀態。該狀態出現的時間很是短暫。

       4) registering slave on master

          在與master創建鏈接後,會出現該狀態。該狀態出現的時間很是短暫。  

       5) requesting binlog dump

           在與master創建鏈接後,會出現該狀態。該狀態出現的時間很是短暫。在這個狀態下,I/O線程向master發送請求,請求binlog,位置從指定的binglog 名字和binglog的position位置開始。

       6) waiting to reconnect after a failed binlog dump request

           若是由於鏈接斷開,致使binglog的請求失敗,I/O線程會進入睡眠狀態。而後按期嘗試重連。嘗試重連的時間間隔,可使用命令"change master to master_connect_trt=X;"改變。

       7) reconnecting after a failed binglog dump request

           I/O進程正在嘗試鏈接master

       8) waiting for master to send event

           說明,已經成功鏈接到master,正等待二進制日誌時間的到達。若是master 空閒,這個狀態會持續很長時間。若是等待的時間超過了slave_net_timeout(單位是秒)的值,會出現鏈接超時。在這種狀態下,I/O線程會人爲鏈接失敗,並開始嘗試重連

       9) queueing master event to the relay log

          此時,I/O線程已經讀取了一個event,並複製到了relay log 中。這樣SQL 線程能夠執行此event

       10) waiting to reconnect after a failed master event read

          讀取時出現的錯誤(由於鏈接斷開)。在嘗試重連以前,I/O線程進入sleep狀態,sleep的時間是master_connect_try的值(默認是60秒)

       11) reconnecting after a failed master event read

          I/O線程正嘗試重連master。若是鏈接創建,狀態會變成"waiting for master to send event"

       12) waiting for the slave sql thread to free enough relay log space

         這是由於設置了relay_log_space_limit,而且relay log的大小已經整張到了最大值。I/O線程正在等待SQL線程經過刪除一些relay log,來釋放relay log的空間。

       13) waiting for slave mutex on exit

          I/O線程中止時會出現的狀態,出現的時間很是短。

 

2. Master_Host: 192.168.1.100

mysql主庫的ip地址

 

3. Master_User: mysync

這個是master上面的一個用戶。用來負責主從複製的用戶,建立主從複製的時候創建的(具備reolication slave權限)。

 

4. Master_Port: 3306

master服務器的端口  通常是3306

 

5. Connect_Retry: 60

鏈接中斷後,從新嘗試鏈接的時間間隔。默認值是60秒。

 

#與master相關的日誌的信息

6. Master_Log_File: mysql-bin.001822

當前I/O線程正在讀取的主服務器二進制日誌文件的名稱。

7. Read_Master_Log_Pos: 290072815

當前I/O線程正在讀取的二進制日誌的位置。

 

#與relay log相關的信息

8. Relay_Log_File: mysqld-relay-bin.005201

當前slave SQL線程正在讀取並執行的relay log的文件名。

9. Relay_Log_Pos: 256529594

當前slave SQL線程正在讀取並執行的relay log文件中的位置;(Relay_Log_File下的Relay_Log_Pos其實一一對應着Relay_Master_Log_File的Exec_Master_Log_Pos。)

10. Relay_Master_Log_File: mysql-bin.001821

當前slave SQL線程讀取並執行的relay log的文件中多數近期事件,對應的主服務器二進制日誌文件的名稱。(說白點就是我SQL線程從relay日誌中讀取的正在執行的sql語句,對應主庫的sql語句記錄在主庫的哪一個binlog日誌中)

 

#slave I/O和SQL線程的狀態(重要)

11. Slave_IO_Running: Yes

I/O線程是否被啓動併成功地鏈接到主服務器上。

12. Slave_SQL_Running: Yes

SQL線程是否被啓動。

 

13. Replicate_Do_DB

  Replicate_Ignore_DB

  Replicate_Do_Table

  Replicate_Ignore_Table

  Replicate_Wild_Do_Table

  Replicate_Wild_Ignore_Table

這些參數都是爲了用來指明哪些庫或表在複製的時候不要同步到從庫,可是這些參數用的時候要當心,由於 當跨庫使用的時候 可能會出現問題。

通常狀況下 ,限制的時候都用Replicate_Wild_Ignore_Table這個參數。

 

14. Last_Errno: 0

  Last_Error

slave的SQL線程讀取日誌參數的的錯誤數量和錯誤消息。錯誤數量爲0而且消息爲空字符串表示沒有錯誤。

若是Last_Error值不是空值,它也會在從屬服務器的錯誤日誌中做爲消息顯示。 

 

15. Skip_Counter: 0

SQL_SLAVE_SKIP_COUNTER的值,用於設置跳過sql執行步數。

 

16. Exec_Master_Log_Pos: 256529431

slave SQL線程當前執行的事件,對應在master相應的二進制日誌中的position。(結合Relay_Master_Log_File理解,並且在Relay_Master_Log_File這個值等於Master_Log_File值的時候,Exec_Master_Log_Pos是不可能超過Read_Master_Log_Pos的。)

 

17. Relay_Log_Space: 709504534

全部原有的中繼日誌結合起來的總大小。

 

18. Until_Condition: None

  Until_Log_File:

  Until_Log_Pos: 0

在START SLAVE語句的UNTIL子句中指定的值。

 

Until_Condition具備如下值:

1) 若是沒有指定UNTIL子句,則沒有值

2) 若是從屬服務器正在讀取,直到達到主服務器的二進制日誌的給定位置爲止,則值爲Master

3) 若是從屬服務器正在讀取,直到達到其中繼日誌的給定位置爲止,則值爲Relay

Until_Log_File和Until_Log_Pos用於指示日誌文件名和位置值。日誌文件名和位置值定義了SQL線程在哪一個點停止執行。

 

19. Master_SSL_Allowed: No

  Master_SSL_CA_File: 

  Master_SSL_CA_Path: 

  Master_SSL_Cert: 

  Master_SSL_Cipher: 

  Master_SSL_Key:

  Master_SSL_Verify_Server_Cert: No 

  Master_SSL_Crl: 

  Master_SSL_Crlpath:

 

這些字段顯示了被從屬服務器使用加密相關的參數。這些參數用於鏈接主服務器。

Master_SSL_Allowed具備如下值:

1) 若是容許對主服務器進行SSL鏈接,則值爲Yes

2) 若是不容許對主服務器進行SSL鏈接,則值爲No

3) 若是容許SSL鏈接,可是從屬服務器沒有讓SSL支持被啓用,則值爲Ignored。

 

與SSL有關的字段的值對應於–master-ca,–master-capath,–master-cert,–master-cipher和–master-key選項的值。

 

20. seconds_Behind_Master: 2923

這個值是時間戳的差值。是slave當前的時間戳和master記錄該事件時的時間戳的差值。

 

21. Last_IO_Errno: 0

  Last_IO_Error: 

  Last_SQL_Errno: 0

  Last_SQL_Error: 

  最後一次I/O線程或者SQL線程的錯誤號和錯誤消息。

 

22. Replicate_Ignore_Server_Ids: 

主從複製,從庫忽略的主庫服務器Id號。就是不以這些服務器Id爲主庫。

 

23. Master_Server_Id: 1

  Master_UUID: 13ee75bb-99e2-11e6-be4d-b499baa80e6e

  Master_Info_File: /home/data/mysql/master.info

  分別表示主庫服務器id號,主庫服務器的UUID好,還有在從庫中保存主庫服務器相關的目錄位置。

 

24. SQL_Delay: 0

一個非負整數,表示秒數,Slave滯後多少秒於master。

 

25. SQL_Remaining_Delay: NULL

當 Slave_SQL_Running_State 等待,直到MASTER_DELAY秒後,Master執行的事件,此字段包含一個整數,表示有多少秒左右的延遲。在其餘時候,這個字段是NULL。

 

26. Slave_SQL_Running_State: Reading event from the relay log

SQL線程運行狀態:

 1) Reading event from the relay log

線程已經從中繼日誌讀取一個事件,能夠對事件進行處理了。

 2) Has read all relay log; waiting for the slave I/O thread to update it

線程已經處理了中繼日誌文件中的全部事件,如今正等待I/O線程將新事件寫入中繼日誌。

 3) Waiting for slave mutex on exit

線程中止時發生的一個很簡單的狀態。

 

27. Master_Retry_Count: 86400

鏈接主庫失敗最多的重試次數。

 

28. Master_Bind: 

slave從庫在多網絡接口的狀況下使用,以肯定用哪個slave網絡接口鏈接到master。

 

29. Last_IO_Error_Timestamp: 

  Last_SQL_Error_Timestamp: 

    最後一次I/O線程或者SQL線程錯誤時的時間戳。

 

#GTID模式相關

30. Retrieved_Gtid_Set: 

  獲取到的GTID<IO線程>

 

  Executed_Gtid_Set: 

  執行過的GTID<SQL線程>

 

  Auto_Position: 0

 

 

 

理解與應用

 

 一、爲何執行stop slave; 再start slave;能夠繼續主從關係呢?

 

 其實執行stop slave;就是分別關閉了I/O線程(stop slave IO_THREAD;)和SQL線程(stop slave SQL_THREAD;),I/O線程會維護master.info信息的更新,SQL線程會維護relay-log.info信息的更新,在執行start slave;時候,會依照master.info和relay-log.info信息,繼續執行I/O線程和SQL線程。

 

 二、怎樣從一個從庫再複製一個新的從庫呢?

 

 步驟:

    1. 在從庫上面stop slave IO_THREAD;關閉IO線程

    2. 等待SQL線程執行完成,當Relay_Master_Log_File和Master_Log_File二進制日誌文件名一致,且Exec_Master_Log_Pos等於Read_Master_Log_Pos值。 

    3. mysqldump導出所須要的庫,到新的從庫服務器,並導入。

    4. 主庫受權replication slave權限給新的從庫

    5. 新的從庫使用change master to命令,master_log_file對應Master_Log_File值,master_log_pos對應Read_Master_Log_Pos值。

    6. 在從庫執行start slave IO_THREAD;和在新的從庫上執行start slave;

相關文章
相關標籤/搜索