I spent most of this Sunday trying to migrate a MySQL 4.x databse to MySQL 5.x. What is easy in theory was impossible in practice: Using the standard mysqldump and import way always produced wrong character encodings in my DB. In fact, the old DB was in latin1, and I wanted the new (5.x) also to be in latin1. But importing the data always produced encodings in utf8 (although MySQL thought it was having latin1). So, I tried almost all but nothing worked but this trick:
- Dump the table definition and import into the new DB. You only need the tables, not the data!
- Convert all tables in the new DB to utf8 as default character encoding:
alter table BLAH convert to character set utf8;. When done, also change the encoding for the entire DB:alter database MYDB character set = utf8;. - Export the table data from the old DB without table creation statements (-t):
mysqldump -t --default-character-set=utf8 MYDB > MYDB.sql. - Import the sql dump as usual.
If you are using PHP to connect to the DB, make sure to tell the database connection it should use utf8 als encoding. With ADODB, this can be done like this:
$db_charset = $db->Execute( "SHOW VARIABLES LIKE 'character_set_database'" ); $db->Execute( "SET NAMES '" . $db_charset->fields['Value'] . "'" );

