Hi friends,
This was my first story on medium, now copying as it is on blogger.
In this note, I’m going to explain you what are the messed up/lost/bad utf-8 characters and how to recover them to original in MySQL db.
What is messed up/lost/bad utf-8 characters?
The messed up or lost or bad characters are those characters which are normal if we convert it to UTF-8, but due to mistakes while import/export, that characters not display properly. Consider following example:
很好的产å“。就是没货了
The above sentence is actually a Chinese sentence, but while import/export from db, it’s get messed up.
How to recover them?
To recover the messed up characters, we should convert them first into binary form, then convert that binary string to UTF-8 string, that’s it!
To do this, use following SQL:
In above SQL, we firstly converted data of varcharColto binary form using MySQL’s CAST function. Then converted that binary string to UTF-8 using CONVERT function.
After executing above SQL, we get following normal string:
很好的产品。就是没货了
Caution
Before doing this, take Backup of your db, because while doing this, normal UTF-8 characters may get messed up 😈
Note
I’ve tested it on table having latin_swedish collation.
This was my first story on medium, now copying as it is on blogger.
In this note, I’m going to explain you what are the messed up/lost/bad utf-8 characters and how to recover them to original in MySQL db.
What is messed up/lost/bad utf-8 characters?
The messed up or lost or bad characters are those characters which are normal if we convert it to UTF-8, but due to mistakes while import/export, that characters not display properly. Consider following example:
很好的产å“。就是没货了
The above sentence is actually a Chinese sentence, but while import/export from db, it’s get messed up.
How to recover them?
To recover the messed up characters, we should convert them first into binary form, then convert that binary string to UTF-8 string, that’s it!
To do this, use following SQL:
In above SQL, we firstly converted data of varcharColto binary form using MySQL’s CAST function. Then converted that binary string to UTF-8 using CONVERT function.
After executing above SQL, we get following normal string:
很好的产品。就是没货了
Caution
Before doing this, take Backup of your db, because while doing this, normal UTF-8 characters may get messed up 😈
Note
I’ve tested it on table having latin_swedish collation.
Comments
Post a Comment
Want to share something? Add here...