Created
May 8, 2018 07:42
-
-
Save b1zzu/242ef5b359b1a21f61ee7ec9da4b4526 to your computer and use it in GitHub Desktop.
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 | |
set -e | |
DATABASE="icinga" | |
CHARSET="latin1" | |
COLLATE="latin1_swedish_ci" | |
echo "Attention!!: Converting database '$DATABASE' and all tables in it to '$CHARSET'" | |
if ! test "$1" == "--convert"; then | |
echo "You should confirm the execution using '--convert' option" | |
echo "Usage: $0 [--convert]" | |
exit 1 | |
fi | |
echo -n "Converting database: '$DATABASE' ..." | |
mysql -BN "$DATABASE" -e "ALTER DATABASE \`$DATABASE\` CHARACTER SET \`$CHARSET\` COLLATE \`$COLLATE\`;" | |
echo " done" | |
for t in $(mysql -BN "$DATABASE" -e "SHOW TABLES;") ; do | |
echo -n " Converting table: '$t' ..." | |
mysql -BN "$DATABASE" -e "ALTER TABLE \`$t\` CONVERT TO CHARACTER SET \`$CHARSET\`;" | |
echo " done" | |
done | |
echo "Finish" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment