Last Updated: February 25, 2016
·
829
· m_wu

UTF8 encoding

In MySql, if you store utf8 encoded data in a latin1 charset, you end up with double encoded utf8 output when querying against the DB with charset set to utf8, having it set to latin1 would resolve the issue, but this will cause issues for newly inserted data.

The solution is to reverse the double encoding by converting the affected columns character sets from latin to binary and then back to utf8.

Example:

ALTER TABLE `MyTable` Modify `Title` text CHARACTER SET latin1;
ALTER TABLE `MyTable` Modify `Title` text CHARACTER SET binary;
ALTER TABLE `MyTable` Modify `Title` text CHARACTER SET utf8;