Mysql - select a value from the request "Show main status"

hi How can I select only the position value from the query "SHOW MASTER STATUS" something like

select position from (show master status); 

thanks for your time and help

+3
source share
3 answers

Unfortunately, there is no direct table to request this information.

If you use PHP, you can get it as follows:

$ sql = "SHOW MASTER STATUS";
$ result = mysql_query ($ sql);
$ row = mysql_fetch_assoc ($ result);
$ pos = $ row ["Position"];

If you need it using shell scripts, you do the following:

POS = `mysql -h... -u... -p... -A -skip-column-names -e "SHOW MASTER STATUS;" | awk '{print $2}' `

!!!

+5

Linux , Seconds_Behind_Master.

 mysql -h 127.0.0.1 -u root -e 'show slave status\G' | grep 'Seconds_Behind_Master';
0

In a Linux bash script, you can try the command below through the mysql client to get the file and position

For file:

mysql -u username -p password -h IP -P Port -e "show master status" | grep "File"| cut -d ":" -f2

For position

mysql -u username -p password -h IP -P Port -e "show master status" | grep "Position"| cut -d ":" -f2
0
source

All Articles