在从库上,使用show slave status,可以查看主从复制状态。
包括主库定制,IO thread、 SQL thread连接状态,以及bin log位置等。
>show slave status\G
*************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: sh-dba-mysql-009
Master_User: repl
Master_Port: 3306
Connect_Retry: 10
Master_Log_File: mysql-bin.000001
Read_Master_Log_Pos: 525
Relay_Log_File: relay.000002
Relay_Log_Pos: 738
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: 525
Relay_Log_Space: 935
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: 4092246
Master_UUID: 456f3e13-6000-11e8-8bda-002272a443bb
Master_Info_File: mysql.slave_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: 456f3e13-6000-11e8-8bda-002272a443bb:1-2
Executed_Gtid_Set: 456f3e13-6000-11e8-8bda-002272a443bb:1-2
Auto_Position: 1
Replicate_Rewrite_DB:
Channel_Name:
Master_TLS_Version:
1 row in set (0.00 sec)
Master_Info_File
其中的选项 Master_Info_File 表示master.info 信息的位置,可以是文件,也可以是数据表。
Master_Info_File 为 mysql.slave_master_info数据表。
日志位点信息
从以上信息中,可以整理出三套日志位点信息。
选项 | 说明 |
---|---|
Master_Log_File | I/O线程正在读取的主库日志文件 |
Read_Master_Log_Pos | 在当前的主库日志文件中,I/O线程已经读取的日志位置 |
Relay_Log_File | SQL线程正在读取和执行的中继日志文件 |
Relay_Log_Pos | 在当前的中继日志文件中,SQL线程已经读取和执行的中继日志坐标 |
Relay_Master_Log_File | SQL线程最近执行的事件所在的主库日志文件 |
Exec_Master_Log_Pos | SQL线程已经读取和执行的主库日志位置 |
Last_IO_Errno 和 Last_IO_Error
Last_IO_Errno 和 Last_IO_Error表示导致IO线程停止的最近的错误码和错误信息。
错误码为0, 错误信息为空, 表示没有错误。如果IO线程出错,错误信息也会出现从库的错误日志。
Last_IO_Error_Timestamp
Last_IO_Error_Timestamp 是最近一次IO 线程出现错误的时间。例如:
Last_IO_Error_Timestamp: 200129 12:29:28
执行 RESET MASTER 或者 RESET SLAVE会清空这些信息。
Last_SQL_Errno,和Last_SQL_Error
表示导致SQL线程停止的最近的错误码和错误信息。
错误码为0, 错误信息为空, 表示没有错误。如果SQL线程出错,错误信息也会出现从库的错误日志。
Last_SQL_Errno 和Last_SQL_Error 具体定义见链接B.3.1 Server Error Message Reference。
执行 RESET MASTER 或者 RESET SLAVE会清空这些信息。
Last_SQL_Error_Timestamp
是最近一次SQL线程出现错误的时间,格式同IO线程Last_IO_Error_Timestamp 。
Last_Errno和Last_Error
Last_Errno和Last_Error 是Last_SQL_Errno 和 Last_SQL_Error 别名。
执行 RESET MASTER 或者 RESET SLAVE会清空这些信息。
参考
13.7.5.34 SHOW SLAVE STATUS Statement
B.3.1 Server Error Message Reference
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· AI与.NET技术实操系列:基于图像分类模型对图像进行分类
· go语言实现终端里的倒计时
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· 25岁的心里话
· ollama系列01:轻松3步本地部署deepseek,普通电脑可用
· 按钮权限的设计及实现
2018-02-24 Go随机数的使用