本文提供兩條核心命令,用於快速核對主從同步狀態與連接數配置:
SHOW GLOBAL STATUS LIKE 'Thread%';
+-------------------+-------+
| Variable_name | Value |
+-------------------+-------+
| Threads_connected | 107 |
| Threads_running | 104 |
| Threads_created | 3252 |
| Threads_cached | 0 |
+-------------------+-------+
SHOW VARIABLES LIKE 'max_connections';
+-----------------+-------+
| Variable_name | Value |
+-----------------+-------+
| max_connections | 2000 |
+-----------------+-------+
-- 主庫
SHOW MASTER STATUS\G;
-- 從庫
SHOW SLAVE STATUS\G;
-- 重點關注:
-- Slave_IO_Running: Yes
-- Slave_SQL_Running: Yes
-- Seconds_Behind_Master: 0
-- Last_SQL_Error: (空)
-- Relay_Log_Space: 中繼日志總大小
#!/bin/bash
echo "=== Master Status ==="
mysql -e "SHOW MASTER STATUS\G"
echo -e "\n=== Slave Status ==="
mysql -e "SHOW SLAVE STATUS\G"
echo -e "\n=== Connection Health ==="
mysql -e "SHOW GLOBAL STATUS LIKE 'Thread%'; SHOW VARIABLES LIKE 'max_connections';"
建議納入監控系統(Prometheus + mysqld_exporter / Zabbix 模板)定時採集,設置告警閾值:Seconds_Behind_Master > 30 或 Slave_SQL_Running != Yes 即報警。