Skip to content

Instantly share code, notes, and snippets.

@wolffc
Created December 9, 2014 10:35
Show Gist options
  • Save wolffc/108cf972be3b94be5d85 to your computer and use it in GitHub Desktop.
Save wolffc/108cf972be3b94be5d85 to your computer and use it in GitHub Desktop.
Exports a dump as latin1 and reimport it as utf8 (no convertsion done) this script is usefull if you have allready written utf-8 data to latin1 tables.
#!/bin/bash
## This script Converts the Typo3 Database to the Correct encoding
## by Exporting the database converting it and importing it agaion;
## CONFIGURATION:
DATE=$(date +"%Y%m%d%H%M")
FILENAME="temp_mysqldump_for_utf8conversion_$DATE.sql"
if [ -n "$1" ] || [-n "$2"]
then
echo "Create dump"
mysqldump --opt --default-character-set=latin1 -u $1 -p $2 > $FILENAME
cp $FILENAME $FILENAME.org
echo "using sed to replace encding"
sed -i 's/latin1/utf8/g' $FILENAME
echo "set Default Charset in Database"
mysql -u $1 -p --execute="ALTER DATABASE $2 DEFAULT CHARACTER SET utf8 DEFAULT COLLATE utf8_general_ci" $2
echo "import"
mysql -u $1 -p $2 < $FILENAME
echo "Your Database Should Be Upgraded"
else
echo "This script Expects to Parameter USERNAME & DATABASE"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment