Pages

Thursday, April 24, 2014

Fix String Encoding error with Mysql



The reason was apparently that the database (and especially the database tables) had the wrong character set. Switching the collation of the database alone did not help. Inspection of the database tables showed that each table still had the latin1 charset, which can not store all utf8 characters:
mysql> show table status;
+----------+--------+-------------------+ ..
| Name     | Engine | Collation         | ..
+----------+--------+-------------------+ ..
| my_table | InnoDB | latin1_swedish_ci | ..
Therefore I altered the character set of the table directly:
ALTER TABLE my_table CONVERT TO CHARACTER SET utf8;
Then it finally worked, and the character set is how utf8
   mysql> show table status;
    ... +-------------------+ ..
    ... | Collation         | .. 
    ... +-------------------+ ..
    ....| utf8_general_ci   | ..

No comments:

Post a Comment