How to capture a column values form SHOW SLAVE STA

2019-09-12 14:30发布

问题:

I need to capture a value of "seconds_behind_master" column.

SHOW SLAVE STATUS;

How to achieve it ?

回答1:

In a shell script or on the command line on Linux you could:

SECONDS_BEHIND=$(mysql -usome_user -psome_pass -e "show slave status" -E | grep "Seconds_Behind_Master:" | cut -d: -f2)


回答2:

SECONDS=$(mysql -uuser -ppass -Pport -e"show slave status\G" grep Seconds_Behind_Master | awk '{print $2}')