查看mysql数据库表大小

时间:2021-06-19 03:21:58
#!/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


本文出自 “宅鸟乐园” 博客,请务必保留此出处http://birdinroom.blog.51cto.com/7740375/1404332