快速查询mysql中每个表的数据量
脚本如下:
#!/bin/bash
mysqlhost=127.0.0.1
mysqluser=root
mysqlpassword=123456
#grep -E test表示仅查询test库
for onedb in $(mysql -h $mysqlhost -u$mysqluser -p$mysqlpassword -e "show databases;" 2>/dev/null |grep -E test);do
for onetab in $(mysql -h $mysqlhost -u$mysqluser -p$mysqlpassword $onedb -e "show tables" 2>/dev/null |grep -v 'Tables_in_');do
onetablength=$(mysql -h $mysqlhost -u$mysqluser -p$mysqlpassword $onedb -e "select count(1) from $onetab" 2>/dev/null |grep -v 'count')
#如果需要生成表格,可以在$onetab和$onetablenth后各加","转为csv格式,再用office转换为excel,\t表示Tab空格
echo -e "$onedb.$onetab\t$onetablength"
done
done