User User name Password  
   
Sunday 8.11.2009 / 01:43 AM
Search AfterDawn.com:        In English   Suomeksi   På svenska
afterdawn.com / profiles / personal safety valve / blog archive / moving utf-8 encoded data from latin1 table to another latin1 table.. /
Home Blog Pictures Shoutbox Links

Moving UTF-8 encoded data from latin1 table to another latin1 table..

20 May 2008 9:34 (Edited: 20 May 2008 9:34)

Encountered weird problem today, when moving data from an ancient Wordpress installation to AfterDawn's own table structure. Apparently, for whatever reason, WP's tables were set by default to be in latin1 encoding, but the data that WP inserted to those tables was in UTF8 format.

Now, our data -- and site outputting -- is in latin1, so moving that data straight from table to table simply cocks up, as then all special characters are shown incorrectly on site.

Googled stuff and found couple of solutions, but these were related to a situation where people wanted simply to change the WP's tables to be in UTF-8 format (as the data was already in that format). These solutions typically included changing text columns to binary format (BINARY or BLOB) so that they wouldn't get converted by MySQL when changing the table's character encoding.

Now, figured out the solution to this: Lets simply follow the instructions first, by converting the text columns to BLOBs, then converting the table to be truly UTF8, then convert the BLOBs back to text columns and finally to convert the table's character encoding to latin1 (which then triggers the automatic conversion of text data by MySQL, exactly the thing we avoided when we converted the columns to BLOBs).

So, basically this should do the trick:

alter table wp_posts_copy modify post_title blob;
alter table wp_posts_copy modify post_content blob;
...etc, all text-based columns...

alter table wp_posts_copy charset=utf8;

alter table wp_posts_copy modify post_title text character set utf8;
alter table wp_posts_copy modify post_content text character set utf8;
...etc, all text-based columns...

alter table wp_posts_copy charset=latin1;

alter table wp_posts_copy modify post_title text character set latin1;
alter table wp_posts_copy modify post_content text character set latin1;
...etc, all text-based columns...

And now you can run the script or SQL statement that copies the data from 'wp_posts_copy' table to your target table that is in latin1 format.

Tags: alter  conversion  convert  latin1  mysql  table  utf-8  utf8 

 

User comments

  • by Ketola @ 20 May 2008 9:37

    Hooray for ugly.. I mean eleganthacks =)


Post your comment

In order to post your comments here, you need be logged in to our system. Simply follow this link in order to login and to post your comments here.

Digital video: AfterDawn.com | AfterDawn Forums
Music: MP3Lizard.com
Gaming: Blasteroids.com | Blasteroids Forums | Compare game prices
Software: Software downloads
Blogs: User profile pages
RSS feeds: AfterDawn.com News | Software updates | AfterDawn Forums
International: AfterDawn in Finnish | AfterDawn in Swedish | download.fi
Navigate: Search | Site map
About us: About AfterDawn Ltd | Advertise on our sites | Rules, Restrictions, Legal disclaimer & Privacy policy
Contact us: Send feedback | Contact our media sales team
 
  © 1999-2009 by AfterDawn Ltd.