快速查询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

 

posted @ 2020-10-14 22:04  小雨淅淅o0  阅读(938)  评论(0编辑  收藏  举报