Created
December 23, 2010 15:41
-
-
Save chorn/753132 to your computer and use it in GitHub Desktop.
Check all of the databases and tables on a mysql host.
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 | |
USER="root" | |
PASS="" | |
HOST="localhost" | |
TYPE="QUICK" | |
usage() { | |
echo "$0 [--host hostname] [--user username] [--pass password] [--type {valid mysql check table type}]" | |
echo " [--scan {scans ~/.my.cnf for user & password]" | |
exit 0 | |
} | |
while [[ $# -gt 0 ]] ; do | |
curr_arg="$1" ; shift | |
if [[ $# -gt 0 ]] ; then next_arg="$1" ; shift ; else next_arg="" ; fi | |
case "$curr_arg" in | |
-u|--user|--username) USER=$next_arg ;; | |
-p|--pass|--password) PASS=$next_arg ;; | |
-t|--type) TYPE=$next_arg ;; | |
-h|--host|--hostname) HOST=$next_arg ;; | |
-s|--scan) | |
USER=`grep '^user=' ~/.my.cnf | sed -e 's/^user=//'` | |
PASS=`grep '^password=' ~/.my.cnf | sed -e 's/^password=//'` | |
;; | |
*) usage ;; | |
esac | |
done | |
AUTH="-u${USER} -p${PASS} -h${HOST}" | |
for db in `mysql $AUTH -Be "SHOW DATABASES" | grep -Ev '(information_schema|Database)'` ; do | |
for table in `mysql $AUTH -Be "SHOW TABLES" "$db" | grep -v Tables_in` ; do | |
mysql $AUTH "$db" -Be "CHECK TABLE $table $TYPE" | grep -Ev "(Msg_text|doesn't support check)" | |
done | |
done | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment