mysql slave 线程 简书_【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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值