Calculating bytes to MB
The mysqladmin command returns the values in bytes. I will like to see the value in MB if it is greater than 1 MB (1048576 bytes).
$ mysqladmin variables
+--------------------开发者_开发百科-------------+----------------------------------+
| Variable_name | Value |
+---------------------------------+----------------------------------+
| auto_increment_increment | 1 |
| auto_increment_offset | 1 |
...
| interactive_timeout | 14400 |
| join_buffer_size | 10481664 |
| key_buffer_size | 1073741824 |
I can save and calculate each variable one at a time. But how do I show all the values in MB?
myval1=$(((`mysqladmin variables | grep '\<key_buffer_size\>' | awk '{print $4}'`)/1048576))
Off the top of my head, something like this would work:
#!/bin/bash
if [ "$1" = variables ]; then
/moved/elsewhere/mysqladmin $* | awk '{ sz=$4; if (sz>1048576)
{ sz=sz/1048576 "Mb"; }
print $1 $2 $3 sz $5; }'
else
/moved/elsewhere/mysqladmin $*
fi
精彩评论