統計データベース内の各テーブルのロー数

763 ワード

#!/bin/bash
username="root"
password="bab5ebf43e"
HOSTNAME="localhost"
PORT="3306"
 
mysql -h${HOSTNAME}  -P${PORT} -u $username -p"$password" -NBe "SHOW DATABASES;" | grep -v 'lost+found' | grep -v 'performance_schema'  | grep -v 'mysql' | grep -v 'information_schema' | while read database ; do
mysql -h${HOSTNAME}  -P${PORT} -u $username -p"$password" -NBe "SHOW TABLES;" $database | while read -a row ; do
tablename=${row[0]}
 
cnt=`mysql -h${HOSTNAME}  -P${PORT} -u $username -p"$password" -NBe "select count(*) from $database.$tablename"`
echo "$database.$tablename count is $cnt" >> 6666
 
done
done