Created
October 22, 2012 20:52
-
-
Save motiejus/3934170 to your computer and use it in GitHub Desktop.
Convert several MySQL databases to MEMORY storage
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/sh | |
set -e | |
usage() { | |
echo "Usage: $0 MYSQL_USER MYSQL_PASSWORD PREFIX" | |
echo | |
echo "Converts as many as possible SSP MySQL tables to MEMORY" | |
echo | |
} | |
main() { | |
USER=$1 | |
PASS=$2 | |
PREFIX=$3 | |
MYSQL="mysql -u${USER}" | |
if [ "${PASS}" != "NONE" ]; then | |
MYSQL="$MYSQL -p${PASS}" | |
fi | |
DBs=`Mysql "SHOW DATABASES" | sed -e '1d' | grep ^${PREFIX}` | |
for db in $DBs; do | |
tbls=`Mysql $db "SHOW TABLES" | sed -e '1d'` | |
for tbl in $tbls; do | |
code= | |
ret=`Mysql $db "ALTER TABLE $tbl ENGINE = MEMORY" 2>&1` || code=$? | |
if [ -n "$code" ]; then | |
echo "Error ($db:$tbl): $ret" | |
else | |
echo "Converted ($db:$tbl)" | |
fi | |
done | |
done | |
} | |
Mysql() { | |
if [ $# -eq 1 ]; then | |
echo "$1" | $MYSQL; | |
else | |
echo "$2" | $MYSQL $1; | |
fi | |
} | |
if [ $# -ne 3 ]; then | |
usage | |
exit 1 | |
else | |
main $1 $2 $3 | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment