Convert Latin1 Characters in a UTF8 Table to UTF8
You've encountered an issue where characters with diacritics (e.g., "Jáuò Iñe") were incorrectly stored in a UTF8 table due to a missing "mysql_set_charset('utf8')" call.
To resolve this, you're attempting to convert the affected rows using "mb_convert_encoding" and "iconv." However, these methods are failing to capture characters beyond the first "illegal" character (represented as "ă" in the example).
The recommended approach to correct the data is to use the MySQL function:
convert(cast(convert(name using latin1) as binary) using utf8)
Explanation:
In some cases, the inner conversion may not be necessary, as the data may already be stored in a binary format suitable for conversion to UTF-8. Testing both options should determine the correct approach for your situation.
Disclaimer: All resources provided are partly from the Internet. If there is any infringement of your copyright or other rights and interests, please explain the detailed reasons and provide proof of copyright or rights and interests and then send it to the email: [email protected] We will handle it for you as soon as possible.
Copyright© 2022 湘ICP备2022001581号-3