Skip to content

Instantly share code, notes, and snippets.

@FreeSS
Forked from sorohan/check-mysql-disabled-keys.sh
Last active December 5, 2017 09:12
Show Gist options
  • Save FreeSS/1f30797ae36a87d44bb2dc4ba41dd11b to your computer and use it in GitHub Desktop.
Save FreeSS/1f30797ae36a87d44bb2dc4ba41dd11b to your computer and use it in GitHub Desktop.
Checks all databases/tables in mysql for disabled keys.
#!/bin/bash
#
# Check all databases/tables in mysql for disabled keys.
#
MYSQL="mysql -uUSER -pPASS"
dbs=$(echo "show databases" | $MYSQL -N)
for db in $dbs; do
tables=$(echo "show tables" | $MYSQL -N $db)
for tb in $tables; do
indexes=$(echo "show indexes from $db.$tb" | $MYSQL -N | grep disabled | awk '{print $3}')
for i in $indexes; do
echo "disabled index: $db.$tb.$i"
done
done
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment