Last active
May 27, 2017 03:44
-
-
Save sanmai/5120f358894c0fe13fe181d59ffc6d96 to your computer and use it in GitHub Desktop.
Warm up MySQL caches: `./warm-up-mysql.sh db-name`
This file contains hidden or 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 | |
echo "SELECT | |
CONCAT('SELECT ',MIN(c.COLUMN_NAME),' FROM ',c.TABLE_NAME,' WHERE ',MIN(c.COLUMN_NAME),' IS NOT NULL;') | |
FROM | |
information_schema.COLUMNS AS c | |
LEFT JOIN ( | |
SELECT DISTINCT | |
TABLE_SCHEMA,TABLE_NAME,COLUMN_NAME | |
FROM | |
information_schema.KEY_COLUMN_USAGE | |
) AS k | |
USING | |
(TABLE_SCHEMA,TABLE_NAME,COLUMN_NAME) | |
WHERE | |
c.TABLE_SCHEMA = '$1' | |
AND k.COLUMN_NAME IS NULL | |
GROUP BY | |
c.TABLE_NAME;" | mysql | grep -v 'CONCAT(' | \ | |
while read i ; do | |
echo -n $i | sed 's/.*FROM \(.*\) WHERE.*/\1/' | |
echo -n " + "; | |
echo $i | mysql | wc -l; | |
done; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment