How to migrate MySQL latin1_swedish_ci to utf8_general_ci

Looks like simple operation but it took mi some time to figure out correct way of doing this.
Remember before doing any of this operation save plain sql dump in safe place in case you mess up something.

Run on command line following commands


1
2
3
mysqldump -u root -p --default-character-set=latin1 --skip-set-charset table_name > dump.sql
sed -i -e "s/latin1/utf8/g" dump.sql
mysql -uroot -p --default-character-set=utf8 table_name < dump.sql
If you still having problems with encoding you can try to set

1
2
3
4
5
6
7
[mysqld]
default-character-set = utf8
init-connect='SET NAMES utf8'
character-set-server = utf8

[mysql]
default-character-set = utf8
in your MySQL configutration file.

Leave a Reply

Your email address will not be published. Required fields are marked *