3

hi How can i select just the position value from the 'SHOW MASTER STATUS' query exp something like

select position from (show master status); 

thanks for your time and help

Khaled_Jamel
  • 71
  • 2
  • 9

3 Answers3

5

Unfortunately, there is no direct table to query that info.

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

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

If you need it via shell scripting you do the following:

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

Give it a Try !!!

RolandoMySQLDBA
  • 41,574
  • 15
  • 86
  • 128
  • thank you, thank you, thank you Rolando i am writing a shell scipt so i tryed the shell command and and it give me what i am looking for just a small correction in the command for other vesitor (--skip-column-names) – Khaled_Jamel Mar 07 '11 at 19:46
0

In Linux you can type the following command in the terminal this will give you the single value of Seconds_Behind_Master.

 mysql -h 127.0.0.1 -u root -e 'show slave status\G' | grep 'Seconds_Behind_Master';
Makyen
  • 27,758
  • 11
  • 68
  • 106
Sanaullah
  • 11
  • 1
  • 1
  • 3
0

In Linux bash script you can try below command through 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
Andronicus
  • 23,098
  • 14
  • 38
  • 73