Last Updated: February 25, 2016
·
581
· agvstin

Fix bad encoding on MySQL

Today I had to fix a mysql table where a latin1 column was filled with utf8 encoded data.

The trick was to convert the data back to binary and cast it as utf8, to let know mysql it's utf8 encoded and to convert it properly

update tableName
set fieldName = cast(convert(fieldName, binary) AS CHAR CHARACTER SET utf8);

Hope it helps!