Skip to content

Instantly share code, notes, and snippets.

@millipedia
Last active February 2, 2017 09:51
Show Gist options
  • Save millipedia/9803692 to your computer and use it in GitHub Desktop.
Save millipedia/9803692 to your computer and use it in GitHub Desktop.
Fix mangled chars in MySQL DB. Original info here http://jonisalonen.com/2010/mysql-character-encoding/
//general case is:
update table set column = convert(binary column using utf8);
// if we've just moved a cmsms db then this is a good start
// but you'll have to do any module specific bits.
update cms_content_props set content = convert(binary content using utf8);
update cms_htmlblobs set html = convert(binary html using utf8);
update cms_module_news set news_data = convert(binary news_data using utf8);
update cms_module_news set summary = convert(binary summary using utf8);
@millipedia
Copy link
Author

This also seems to work well:

update cms_module_QuakersInTheWorld set qContent = convert(cast(convert(qContent using latin1) as binary) using utf8)

one of these days I should investigate what it's doing.

@millipedia
Copy link
Author

And this seems to work best of all so far:
Convert to BLOB first and then back to text (or whatever) in UTF8

ALTER TABLE cms_module_QuakersInTheWorld CHANGE qSummary qSummary BLOB;
ALTER TABLE cms_module_QuakersInTheWorld CONVERT TO CHARACTER SET utf8, CHANGE qSummary qSummary TEXT;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment