Skip to content

Instantly share code, notes, and snippets.

@Bogdaan
Created January 6, 2014 13:22
Show Gist options
  • Save Bogdaan/8282810 to your computer and use it in GitHub Desktop.
Save Bogdaan/8282810 to your computer and use it in GitHub Desktop.
Convert mysql database tables to "innodb+utf8"
#/usr/bin/env bash
DBS=$1
USER=$2
PASS=$3
if [[ -z $DBS || -z $USER || -z $PASS ]];
then
echo 'Usage: ./mysql-innodb-utf.sh DB USER PASS';
exit 1;
fi;
mysql --database=${DBS} -u${USER} -p${PASS} -B -N -e "SHOW TABLES" |
awk '{print "SET foreign_key_checks = 0; ALTER TABLE ", $1, " CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci; ALTER TABLE ",$1 ," ENGINE=INNODB; SET foreign_key_checks = 1; "}' |
mysql --database=${DBS} -u${USER} -p${PASS}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment