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

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM