#!/bin/bash
echo "needed parameters are: dbname username [password]"
echo "will convert DB \"$1\" with user \"$2\""
echo "press enter to continue"
read

# script according to http://wiki.typo3.org/UTF-8_support#convert_databases_to_utf8
echo ALTER DATABASE $1 CHARACTER SET
echo "ALTER DATABASE $1 CHARACTER SET utf8 COLLATE utf8_general_ci;" | mysql -u $2 -p$3
echo mysqldump
#                                            v---- here insert utf8 if utf8 is stored in latin-fields
#                                            v---- hier utf8 eintragen wenn utf8 in latin-feldern gespeichert ist
mysqldump -u $2 -p$3 --default-character-set=latin1 --databases $1 > $1.orig.sql
echo copy
cp $1.orig.sql $1.temp.sql
echo DEFAULT CHARSET
sed -i 's/DEFAULT CHARSET=latin1/DEFAULT CHARSET=utf8/gI' $1.temp.sql
echo SET NAMES 
sed -i 's/SET NAMES latin1/SET NAMES utf8/gI' $1.temp.sql
echo CHARACTER SET
sed -i 's/CHARACTER SET latin1/CHARACTER SET utf8/gI' $1.temp.sql

echo "latin1_german[12]_ci -\> utf8"
sed -i 's/COLLATE latin1_german[12]_ci/COLLATE utf8_unicode_ci/gI' $1.temp.sql
echo \*
sed -i 's/COLLATE=latin1_german[12]_ci/COLLATE=utf8_unicode_ci/gI' $1.temp.sql

echo "latin1_swedish_ci -\> utf8"
sed -i 's/COLLATE latin1_swedish_ci/COLLATE utf8_unicode_ci/gI' $1.temp.sql
echo \*
sed -i 's/COLLATE=latin1_swedish_ci/COLLATE=utf8_unicode_ci/gI' $1.temp.sql

#echo InnoDb
#sed -i 's/ENGINE=MyISAM/ENGINE=InnoDb/g' $1.new.sql
echo character_set_client
grep -v character_set_client <$1.temp.sql > $1.new.sql
echo remove temp
rm $1.temp.sql
echo reload
mysql -u $2 -p$3 --default-character-set=utf8 $1 < $1.new.sql
echo zip sql
# store just in case we might need them if something goes wrong
gzip $1.orig.sql
echo \*
gzip $1.new.sql
echo done!
 
Ihre aktuelle Seitenauswahl:  
>>>