前言:大家平时在检查主从复制的时候基本上都会使用 show slave status来看主从复制的情况,那么你真的读懂每个指标项了吗?
一、status指标解读
root@localhost [(none)]>show slave status\GERROR 2006 (HY000): MySQL server has gone awayNo connection. Trying to reconnect...Connection id: 7Current database: *** NONE ****************************** 1. row ***************************Slave_IO_State: Waiting for master to send eventMaster_Host: 192.168.50.3Master_User: replMaster_Port: 3306Connect_Retry: 60Master_Log_File: mysql-bin.000001Read_Master_Log_Pos: 728Relay_Log_File: relay-bin.000002Relay_Log_Pos: 941Relay_Master_Log_File: mysql-bin.000001Slave_IO_Running: YesSlave_SQL_Running: YesReplicate_Do_DB:Replicate_Ignore_DB:Replicate_Do_Table:Replicate_Ignore_Table:Replicate_Wild_Do_Table:Replicate_Wild_Ignore_Table:Last_Errno: 0Last_Error:Skip_Counter: 0Exec_Master_Log_Pos: 728Relay_Log_Space: 1142Until_Condition: NoneUntil_Log_File:Until_Log_Pos: 0Master_SSL_Allowed: NoMaster_SSL_CA_File:Master_SSL_CA_Path:Master_SSL_Cert:Master_SSL_Cipher:Master_SSL_Key:Seconds_Behind_Master: 0Master_SSL_Verify_Server_Cert: NoLast_IO_Errno: 0Last_IO_Error:Last_SQL_Errno: 0Last_SQL_Error:Replicate_Ignore_Server_Ids:Master_Server_Id: 1003306Master_UUID: dff47046-3ad5-11e8-86fe-080027de0e0eMaster_Info_File: /storage/mysql/data/master.infoSQL_Delay: 0SQL_Remaining_Delay: NULLSlave_SQL_Running_State: Slave has read all relay log; waiting for more updatesMaster_Retry_Count: 86400Master_Bind:Last_IO_Error_Timestamp:Last_SQL_Error_Timestamp:Master_SSL_Crl:Master_SSL_Crlpath:Retrieved_Gtid_Set: dff47046-3ad5-11e8-86fe-080027de0e0e:1-3Executed_Gtid_Set: dff47046-3ad5-11e8-86fe-080027de0e0e:1-3Auto_Position: 1Replicate_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 |
二、日常运维注意点
在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
