Skip to content

Instantly share code, notes, and snippets.

@isotopp
Last active February 19, 2024 16:09
Show Gist options
  • Save isotopp/3f3f23f24f2e21e35ffa583768bf6b77 to your computer and use it in GitHub Desktop.
Save isotopp/3f3f23f24f2e21e35ffa583768bf6b77 to your computer and use it in GitHub Desktop.
Fix Mojibake
--- the table.the_field contains mojibake
update the_table
set the_field =
case
-- conversion may fail, returning NULL. In this case, retain original data
when convert(cast(convert(the_field using latin1) as binary) using utf8mb4) is null then the_field
-- conversion success -> choose the demojibaked data
else convert(cast(convert(the_field using latin1) as binary) using utf8mb4)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment