Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Dump the old database as latin1, because ironically, mysqldump defaults to utf8.
- mysqldump --default-character-set=latin1 db > db.dump
- # If you need to convert a MySQL dump from one character set to another, use iconv.
- iconv -f LATIN1 -t UTF-8 < db.dump > db.dump
- # If you've been running mysqldump without parameters on a latin1 instance, you can convert the dump from UTF8 to latin1 to correct it.
- iconv -f UTF-8 -t LATIN1 < db.dump > db.dump
- # Rewrite the dump to say 'utf8' and 'utf8_unicode_ci' in all the right places.
- sed -e 's/SET NAMES latin1/SET NAMES utf8/g' -i db.dump
- sed -e 's/CHARSET=latin1/CHARSET=utf8 COLLATE=utf8_unicode_ci/g' -i db.dump
- # Create a new database with the correct parameters.
- create database db character set utf8 collate utf8_unicode_ci;
- # Verify it.
- show create database db;
- # Pipe the converted database dump into MySQL.
- mysql -h hostname --default-character-set=utf8 -u root -p db < db.dump
Add Comment
Please, Sign In to add comment