1
2
3
4
5
6
7
8
#!/bin/bash
# create by lhb
# show mysql table size
# date 2012-03-29 09:46
database=cms
user=root
password='123456'
mysql -u${user} -p${password} -e "use $database;show tables;" sed '1d' while read line; do  mysql -u$user -p${password} $database -e "SELECT '${line}',ROUND(SUM(data_length/1024/1024),2) as data_length ,'MB',round(SUM(index_length/1024/1024),2) as index_length,'MB' FROM information_schema.TABLES WHERE information_schema.TABLES.TABLE_SCHEMA = '${database}' AND information_schema.TABLES.TABLE_NAME = '$line'";done grep -v data_length | awk '{print $1"\t"$2$3"\t"$4$5}' sort -nrk2

本文转自birdinroom 51CTO博客,原文链接:http://blog.51cto.com/birdinroom/1404332,如需转载请自行联系原作者