How to access Seconds_Behind_Master from SQL

I would like to access a field Seconds_Behind_Master(as returned by SHOW SLAVE STATUS) from a stored procedure.

I cannot figure out how to get its value inside a variable. None of the usual SET / SELECT syntax seems to work.

Is there any way to do this?

+5
source share
3 answers

Just for writing: it turned out that you can open the cursor for SHOW statements. This allows you to analyze the output and work with it inside the stored procedure.

+2
source

From what I see in the recent documents and MySQL Bug # 37187 , it appears that there is, but SHOW SLAVE STATUSto get to that information.

+2

PHP show slave status hashmap, :

$db = new pdo(
    "mysql:host=your_database_hostname;dbname=your_database_name",
    'your_username', 'your_password');

$sql = 'show slave status';

$query = $db->query($sql);
$res = $query->fetchall();

foreach($res as $item){
    print ">" . $item["Seconds_Behind_Master"];
}

0 , :

>0

I tried for an hour to create a stored procedure for this. I recommend you not to waste time.

0
source

All Articles