dataiotech Labs
dbaguidedbaguideDBAdataxtoolsdataopsphere
Scripts Library/mysql/#26
Script #26
mysql
Replicationread-onlyMin Version: 8.0.22 (eski: `SHOW SLAVE STATUS`)

MySQL Replication Status and Lag Check

Checks IO/SQL thread state, Seconds_Behind_Source and the latest errors. Quickly verifies replica health.

#replication#lag#replica
mysql · sql
-- 1. Replikasyon Durumu (Classic Replica Status)
SHOW REPLICA STATUS\G
-- Alanlar: Replica_IO_Running, Replica_SQL_Running, Seconds_Behind_Source

-- 2. Performance Schema ile (MySQL 8.0+)
SELECT channel_name, service_state, last_error_message
FROM performance_schema.replication_connection_status;

SELECT channel_name, service_state, last_error_message
FROM performance_schema.replication_applier_status_by_worker;
Operational Notes & Remediation Guidance

Verify in a staging environment prior to running in production. This is a read-only diagnostic query; it does not acquire exclusive locks.

Production Safety & Execution Standards
  • This script is designed for read-only diagnostics; it does not alter schema or modify data directly.
  • Prior to executing on production systems under high load, verify the target database version (Min. Version: 8.0.22 (eski: `SHOW SLAVE STATUS`)).
  • Exercise caution with mutating actions (e.g., terminating sessions or dropping indexes) referenced in the notes section.