Convert a MySQL database to UTF8

This is a “script” to convert your latin1 myisam database to utf8 innodb
Dump the database

mysqldump -u root -p database_to_convert > db.latin1.sql

Make a copy of the dump

cp db.latin1.sql db.utf8.sql

Change any default table charset to be utf8

sed -i 's/DEFAULT CHARSET=latin1/DEFAULT CHARSET=utf8/g' db.utf8.sql

Now, remove all field collations for Latin1

sed -i 's/COLLATE=latin1_general_ci//g' db.utf8.sql

Change any MyISAM engines to InnoDB

sed -i 's/ENGINE=MyISAM/ENGINE=InnoDB/g' db.utf8.sql

Re-import the database

mysql -u root -p database_to_convert < db.utf8.sql

And thats it.

Leave a Reply

Your email address will not be published.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>