Fixing Incorrect Encoding In MySQL Databases
I have recently faced an issue while migrating MySQL to a new server where non-English characters show up as gibberish. This was because UTF-8 text was saved in columns encoded as latin1. The solution is simple, convert the field into a BLOB and then back to text with the required type and encoding.
Sometimes you need to do that multiple times, if you do, you need to convert the table back to latin1 and then do the procedure again
1ALTER TABLE _TABLE MODIFY _TABLE.field BLOB;
2ALTER TABLE _TABLE MODIFY _TABLE.field VARCHAR(200) CHARACTER SET utf8;
3
4/* if you have to do this a second time*/
5ALTER TABLE _TABLE MODIFY _TABLE.field VARCHAR(200) CHARACTER SET latin1;
6ALTER TABLE _TABLE MODIFY _TABLE.field BLOB;
7ALTER TABLE _TABLE MODIFY _TABLE.field VARCHAR(200) CHARACTER SET utf8;
About Me
Dev gone Ops gone DevOps. Any views expressed on this blog are mine alone and do not necessarily reflect the views of my employer.
Recent Posts