Skip to content

Instantly share code, notes, and snippets.

@oilbeater
Last active August 29, 2015 14:08
Show Gist options
  • Save oilbeater/2e2036bd54e0b7e6daf0 to your computer and use it in GitHub Desktop.
Save oilbeater/2e2036bd54e0b7e6daf0 to your computer and use it in GitHub Desktop.
Count database row number
#!/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