How to measure MySQL replication delay between 2 MySQL servers ( 1 Master 1 Slave ) ?

Given that two Xeon E5620 grade 1U servers are separate machine in same network segment, using MySQL Community Server 5.1 running in Ubuntu Linux Server 11.04.


In MySQL command line, give command


and see the Seconds_behind_ master value.

Or if you want to script that somehow, the one-liner below returns how many seconds behind master the slave currently is.

mysql -u your_user -e 'SHOW SLAVE STATUS\G' | grep "Seconds_Behi" | awk '{ print $2; }'
  • Cool. May I ask what does the \G mean? – Raptor Nov 28 '11 at 14:00
  • 1
    \G formats the status command output in more human-readable way and in this case makes the grep part easier, too. :) In other words, \G puts each status entry in its own line, without it you get a messy table-like output with ascii graphics and all. – Janne Pikkarainen Nov 28 '11 at 14:02

I guess it depends how accurate you want to be and for what purpose.

I update a record on the master and then do several reads from the slave until I get the updated record. I'm working with a slow connection between the two seperate offices. So 0.1 second resolution is good enough for me.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.