【MySQL】你真的读懂了slave status吗?

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

一、status指标解读

root@localhost [(none)]>show slave status\G
ERROR 2006 (HY000): MySQL server has gone away
No connection. Trying to reconnect...
Connection id:    7
Current database: *** NONE ***

*************************** 1. row ***************************
               Slave_IO_State: Waiting for master to send event
                  Master_Host: 192.168.50.3
                  Master_User: repl
                  Master_Port: 3306
                Connect_Retry: 60
              Master_Log_File: mysql-bin.000001
          Read_Master_Log_Pos: 728
               Relay_Log_File: relay-bin.000002
                Relay_Log_Pos: 941
        Relay_Master_Log_File: mysql-bin.000001
             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: 728
              Relay_Log_Space: 1142
              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: 0
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: 1003306
                  Master_UUID: dff47046-3ad5-11e8-86fe-080027de0e0e
             Master_Info_File: /storage/mysql/data/master.info
                    SQL_Delay: 0
          SQL_Remaining_Delay: NULL
      Slave_SQL_Running_State: Slave has read all relay log; waiting for more updates
           Master_Retry_Count: 86400
                  Master_Bind: 
      Last_IO_Error_Timestamp: 
     Last_SQL_Error_Timestamp: 
               Master_SSL_Crl: 
           Master_SSL_Crlpath: 
           Retrieved_Gtid_Set: dff47046-3ad5-11e8-86fe-080027de0e0e:1-3
            Executed_Gtid_Set: dff47046-3ad5-11e8-86fe-080027de0e0e:1-3
                Auto_Position: 1
         Replicate_Rewrite_DB: 
                 Channel_Name: 
           Master_TLS_Version: 
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

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

指标 注释
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
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 157,198评论 4 359
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 66,663评论 1 290
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 106,985评论 0 237
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 43,673评论 0 202
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 51,994评论 3 285
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 40,399评论 1 211
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 31,717评论 2 310
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 30,407评论 0 194
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 34,112评论 1 239
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 30,371评论 2 241
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 31,891评论 1 256
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 28,255评论 2 250
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 32,881评论 3 233
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 26,010评论 0 8
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 26,764评论 0 192
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 35,412评论 2 269
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 35,299评论 2 260

推荐阅读更多精彩内容