show slave status
Slave_IO_State: Waiting for master to send event
Master_Host: 10.1.1.1
Master_User: rep_user
Master_Port: 3306
Connect_Retry: 10
Master_Log_File: binlog.000026
Read_Master_Log_Pos: 446
Relay_Log_File: relay.000008
Relay_Log_Pos: 589
Relay_Master_Log_File: binlog.000026
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: 446
Relay_Log_Space: 878
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: 2211
#主从复制原理
Slave有两个线程,I/O线程从Master接收二进制日志文件,写入本地的中继日志,SQL线程,读取中继日志,重放。
#show slave status输出的几个重点含义介绍
Slave_IO_Running: Yes #IO进程的运行状态
Slave_SQL_Running: Yes #SQL进程的运行状态
Master_Log_File: binlog.000026 #IO进程读取到了主库的哪个binlog
Read_Master_Log_Pos: 446 #IO进程读到了哪个位置
Relay_Master_Log_File: binlog.000026 #重放的中继日志对应的master二进制文件。表示最近执行的中继日志事件所对应的master日志文件名。
Exec_Master_Log_Pos: 446 #重放到了哪个位置
Relay_Log_File: relay.000008 #保存的中继日志
Relay_Log_Pos: 589 #读取中继日志,到了哪个位置
#判断从库延迟
1.查看IO进程和SQL进程是否为Yes:
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
如果值为No,需要执行start slave,将其启动,然后再次查看show slave status内容,看两个进程的值是否为Yes,若还是No,则看下Last_Error是否有报错,根据具体报错进行相应处理。
2.查看具体延迟情况
(1) 判断IO进程是否有延迟
如果Master_Log_File,Read_Master_Log_Pos与Master 上面的show master status 输出的文件名和位置相等,说明IO进程已经读取到最新的binlog,IO进程无延迟。
(2) 判断sql进程是否有延迟
① 先判断Relay_Master_Log_File与Master_Log_File是否一致,如果Relay_Master_Log_File的值小于Master_Log_File,则说明有延迟。如果二者相等,再做下面的判断。
② 判断下Exec_Master_Log_Pos是否小于Read_Master_Log_Pos,如果等于,说明没有需要重放的内容了,sql进程无延迟。如果前者小于后者,则说明有延迟,此时查看seconds_Behind_Master,一般不等于0.
Seconds_Behind_Master单位是秒,但是这个值并不准确,只是大概反映主从延迟情况。
Seconds_Behind_Master=0 不表示Slave与Master完全同步,而是中继日志执行完了。要判断是否完全同步,还需要判断IO进程是否有延迟。
--本篇文章转自:
show slave status