How to access Seconds_Behind_Master from SQL

mysql, sql

Solution

Just for the record: it has turned out to be possible to open a cursor for SHOW statements. This allows to parse the output and work with it inside a stored procedure.

Problem

I would like to have access to the `Seconds_Behind_Master` field, (as returned by SHOW SLAVE STATUS) from inside a stored procedure. I can't figure out how to get its value inside a variable. None of the usual SET/SELECT syntax seems to work. Is there a way to do that?

Original source