开发者

Mysql - Select value from 'Show master status' query

开发者 https://www.devze.com 2023-02-15 02:43 出处:网络
hi How can i select just the position value from the \'SHOW MASTER STATUS\' query exp something like select position from (show 开发者_开发问答master status);

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


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

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

$sql="SHOW MASTER STATUS";<BR>
$result = mysqli_query($sql);<BR>
$row = mysqli_fetch_assoc($result);<BR>
$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}'\`


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';


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
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号