Created
January 6, 2014 13:22
-
-
Save Bogdaan/8282810 to your computer and use it in GitHub Desktop.
Convert mysql database tables to "innodb+utf8"
This file contains 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
#/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