Created
December 9, 2014 10:31
-
-
Save wolffc/8a0a9cebeb980afcf388 to your computer and use it in GitHub Desktop.
Convert an typo3 database to utf-8
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
#!/bin/bash | |
# | |
# Creates a backup of a database in mirgrates every table to UTF-8 Including Collation | |
# written by christian Wolff [email protected] | |
## Configuration | |
DB_USER=$1 | |
DB_PASS=$2 | |
DB_NAME=$3 | |
if [ -z $DB_USER ] || [ -z $DB_PASS ] || [ -z $DB_NAME ]; then | |
echo "not all required parameters are present" | |
echo "usage: t3x-convert-character-set-to-utf8.sh unsername password database" | |
exit 1; | |
fi | |
## Main Program | |
TIMESTAMP=$(date +%F-%s) | |
FILENAME="dump_$TIMESTAMP.sql"; | |
echo "creating Backup ... $FILENAME" | |
mysqldump -u$DB_USER -p$DB_PASS $DB_NAME > $FILENAME | |
if [ $? -eq 0 ]; then | |
echo "updating database ..." | |
mysql -u$DB_USER -p$DB_PASS --database=$DB_NAME -B -N -e "SHOW TABLES" \ | |
| awk '{print "SET foreign_key_checks = 0; ALTER TABLE", $1, "CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci; SET foreign_key_checks = 1; "}' \ | |
| mysql -u$DB_USER -p$DB_PASS --database=$DB_NAME & | |
else | |
echo "mysql dump failed no changes applied" | |
exit 1 | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment