Last active
August 29, 2015 14:08
-
-
Save oilbeater/2e2036bd54e0b7e6daf0 to your computer and use it in GitHub Desktop.
Count database row number
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash -x | |
# To count row number of each table in a schema | |
# Example: echo 127.0.0.1 root rootpassword rootdatabase | ./count_database.sh 2>/dev/null | |
while read host username password schema; | |
do | |
mysql -h$host -u$username -p$password -Ne "select table_name from information_schema.tables where table_schema='${schema}'"| | |
while read table; | |
do | |
mysql -h$host -u$username -p$password -Ne "select '$schema','$table',count(*) from $schema.$table"; | |
done | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment