前言:大家平时在检查主从复制的时候基本上都会使用 show slave status来看主从复制的情况,那么你真的读懂每个指标项了吗?

一、status指标解读

  1. root@localhost [(none)]>show slave status\G
  2. ERROR 2006 (HY000): MySQL server has gone away
  3. No connection. Trying to reconnect...
  4. Connection id: 7
  5. Current database: *** NONE ***
  6. *************************** 1. row ***************************
  7. Slave_IO_State: Waiting for master to send event
  8. Master_Host: 192.168.50.3
  9. Master_User: repl
  10. Master_Port: 3306
  11. Connect_Retry: 60
  12. Master_Log_File: mysql-bin.000001
  13. Read_Master_Log_Pos: 728
  14. Relay_Log_File: relay-bin.000002
  15. Relay_Log_Pos: 941
  16. Relay_Master_Log_File: mysql-bin.000001
  17. Slave_IO_Running: Yes
  18. Slave_SQL_Running: Yes
  19. Replicate_Do_DB:
  20. Replicate_Ignore_DB:
  21. Replicate_Do_Table:
  22. Replicate_Ignore_Table:
  23. Replicate_Wild_Do_Table:
  24. Replicate_Wild_Ignore_Table:
  25. Last_Errno: 0
  26. Last_Error:
  27. Skip_Counter: 0
  28. Exec_Master_Log_Pos: 728
  29. Relay_Log_Space: 1142
  30. Until_Condition: None
  31. Until_Log_File:
  32. Until_Log_Pos: 0
  33. Master_SSL_Allowed: No
  34. Master_SSL_CA_File:
  35. Master_SSL_CA_Path:
  36. Master_SSL_Cert:
  37. Master_SSL_Cipher:
  38. Master_SSL_Key:
  39. Seconds_Behind_Master: 0
  40. Master_SSL_Verify_Server_Cert: No
  41. Last_IO_Errno: 0
  42. Last_IO_Error:
  43. Last_SQL_Errno: 0
  44. Last_SQL_Error:
  45. Replicate_Ignore_Server_Ids:
  46. Master_Server_Id: 1003306
  47. Master_UUID: dff47046-3ad5-11e8-86fe-080027de0e0e
  48. Master_Info_File: /storage/mysql/data/master.info
  49. SQL_Delay: 0
  50. SQL_Remaining_Delay: NULL
  51. Slave_SQL_Running_State: Slave has read all relay log; waiting for more updates
  52. Master_Retry_Count: 86400
  53. Master_Bind:
  54. Last_IO_Error_Timestamp:
  55. Last_SQL_Error_Timestamp:
  56. Master_SSL_Crl:
  57. Master_SSL_Crlpath:
  58. Retrieved_Gtid_Set: dff47046-3ad5-11e8-86fe-080027de0e0e:1-3
  59. Executed_Gtid_Set: dff47046-3ad5-11e8-86fe-080027de0e0e:1-3
  60. Auto_Position: 1
  61. Replicate_Rewrite_DB:
  62. Channel_Name:
  63. Master_TLS_Version:
  64. 1 row in set (0.00 sec)

下面我们逐个来解读一下:

指标 注释
Slave_IO_State: Waiting for master to send event 表示IO线程的状态
Master_Host: 192.168.50.3 Master的IP地址
Master_User: repl 主从复制的用户
Master_Port: 3306 Master的端口
Connect_Retry: 60 IO thread重连次数
Master_Log_File: mysql-bin.000001 IO thread正在读取的master上的binlog文件
Read_Master_Log_Pos: 728 正在读取的master上的binlog文件位置
Relay_Log_File: relay-bin.000002 执行的本地relay log文件名
Relay_Log_Pos: 941 执行的本地relay log位置
Relay_Master_Log_File: mysql-bin.000001 SQL线程正在执行的master binlog file
Slave_IO_Running: Yes IO thread状态
Slave_SQL_Running: Yes SQL thread状态
Replicate_Do_DB: 指定复制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: 728 执行masterbinlog的位置
Relay_Log_Space: 1142 所有relay log字节数总和
Until_Condition: None 指定复制条件
Until_Log_File: 指定复制到某个文件
Until_Log_Pos: 0 指定复制到某个位置
Seconds_Behind_Master: 0 从库落后主库时间,单位秒,不准确
Last_IO_Errno: 0 最近一次IO thread错误
Last_IO_Error 最近一次IO thread错误详细信息
Last_SQL_Errno: 0 最近一次sql thread错误
Last_SQL_Error: 最近一次sql thread错误详细信息
Replicate_Ignore_Server_Ids: 复制忽略server_id为xxx的实例
Master_Server_Id: 1003306 master server_id
Master_UUID: dff47046-3ad5-11e8-86fe-080027de0e0e master uuid
Master_Info_File: /storage/mysql/data/master.info 记录master信息文件
SQL_Delay: 0 sql延迟多少时间,延迟复制会用到
SQL_Remaining_Delay: NULL 当sql thread状态为Waiting until MASTER_DELAY seconds after master executed event,那么该值表示剩下延迟多少时间
Slave_SQL_Running_State: Slave has read all relay log; waiting for more updates sql thread状态
Master_Retry_Count: 86400 主从复制断开时slave最多能尝试重新连接的次数
Master_Bind: 绑定网卡
Last_IO_Error_Timestamp: io thread 最近一次的错误时间
Last_SQL_Error_Timestamp: sql thread 最近一次的错误时间
Retrieved_Gtid_Set: dff47046-3ad5-11e8-86fe-080027de0e0e:1-3 IO thread获取到的GTID
Executed_Gtid_Set: dff47046-3ad5-11e8-86fe-080027de0e0e:1-3 SQL thread执行的GTID
Auto_Position: 1 使用auto_position,建议还是开启比较方便
Replicate_Rewrite_DB: 复制DB对应关系
Channel_Name: 多源复制的channel name

二、日常运维注意点

  • 在GTID环境下,主从同步延迟观察就非常简单了,我们只需要观察Retrieved_Gtid_Set表示的就是io thread读取到的位置,Executed_Gtid_Set表示的就是sql thread执行到的位置

  • 在非GTID环境下,主从复制观察相对来说稍微麻烦一些,(Master_Log_file, Read_Master_Log_Pos): 表示io thread读取到的master binlog位置;
    Relay_Master_Log_File, Exec_Master_Log_Pos): 表示sql thread已经执行到的位置;
    (Relay_Log_File, Relay_Log_Pos): 表示sql thread执行到的relay log位置

  • Seconds_Behind_Master表示slave延迟master的时间数,并不是很准确,计算公式是:io_thread.timestamp-sql_thread.timestamp