Now a days, UTF-8 is the most used data encoding format, and the fact that your database is not using UTF8 encoding is really annoying, specially additionally when it comes to integrating different systems, that has no one unified encoding format.
So if you think it’s time to change your data encoding to utf8 format, then here what this post is all about.
I’ll list here the steps to do so, i just have to clarify that the main data encoding here is windows-1256 (which is the main Arabic encoding used in web applications), but it’s saved in latin1 encoding in the database (mydata ->windows-1256 -> latin1) ,also note that i’m using Mysql database.
Here are the steps:
mysqldump --default-character-set=latin1 --skip-set-charset -d -uusername -ppassword db_name > db_name_schema.sql
mysqldump --default-character-set=latin1 --skip-set-charset -t -uusername -ppassword db_name > db_name_data.sql
iconv -f windows-1256 -t utf8 db_name_schema.sql > db_name_schema_utf8.sql iconv -f windows-1256 -t utf8 db_name_data.sql > db_name_data_utf8.sql
mysql -uusername -ppassword -e 'CREATE DATABASE new_db DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci'
mysql --default-character-set=utf8 -uusername -ppassword new_db < db_name_schema_utf8.sql mysql --default-character-set=utf8 -uusername -ppassword new_db < db_name_data_utf8.sql
notes
enjoy!!!
hairy mary | March 20th, 2009 at 7:09 pm #
nice work. useful. thx.
Geanciede | May 20th, 2009 at 9:51 am #
Hello Sir:
Thanks for posting these useful infirmation. Keep them coming
Fixing mixed-encoding MySQL dumpfiles with WordPress | May 26th, 2009 at 8:20 pm #
[...] your data has a ‘latin1′ somewhere in it, either edit the dumpfile by hand or read this and dump your schema separate from your data. My data was clean so I just used Sed to replace the [...]