Databases sql Intermediate

MySQL Replication Status Check

Script to check MySQL/MariaDB replication lag and alert if it exceeds threshold.

sql
-- On replica
SHOW REPLICA STATUS;

-- Shell script to check lag
#!/bin/bash
LAG=$(mysql -u root -proot -e 'SHOW REPLICA STATUS' | grep Seconds_Behind_Source | awk '{print $2}')
if [ $LAG -gt 30 ]; then
  echo WARN: Replication lag ${LAG}s
fi

Prerequisites

  • MySQL >= 8
  • Replication configured

Pro Tips

  • → Alert when lag > 30s for write-heavy apps.

Was this module useful?

Share your experience — it helps the team improve.

Leave Feedback

Commercial Licensing

Acquire a production access token or template license for enterprise deployment.

Module Info

Language
sql
Level
Intermediate
Read time
3 min
Published
Sep 2026
License
Commercial License

Newsletter

New modules every week, directly to your inbox.