Skip to content

Instantly share code, notes, and snippets.

@b1zzu
Created May 8, 2018 07:42
Show Gist options
  • Save b1zzu/242ef5b359b1a21f61ee7ec9da4b4526 to your computer and use it in GitHub Desktop.
Save b1zzu/242ef5b359b1a21f61ee7ec9da4b4526 to your computer and use it in GitHub Desktop.
#!/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