{"id":903,"date":"2010-12-24T19:10:00","date_gmt":"2010-12-24T11:10:00","guid":{"rendered":"http:\/\/wp.jiinjoo.com\/?p=903"},"modified":"2010-12-24T19:10:00","modified_gmt":"2010-12-24T11:10:00","slug":"moving-chinese-encoding-utf-8-on-wordpress-from-mysql-4-to-5","status":"publish","type":"post","link":"https:\/\/wp.jiinjoo.com\/?p=903","title":{"rendered":"Moving Chinese encoding (UTF-8) on WordPress from MySQL 4 to 5"},"content":{"rendered":"<p>Upgraded my <a href=\"http:\/\/wp.jiinjoo.com\">WordPress<\/a> and had my Chinese Characters all gone! <\/p>\n<p>After some inspiration from <a href=\"http:\/\/alexking.org\/blog\/2008\/03\/06\/mysql-latin1-utf8-conversion\" target=\"_blank\">http:\/\/alexking.org\/blog\/2008\/03\/06\/mysql-latin1-utf8-conversion<\/a> and <a href=\"http:\/\/codex.wordpress.org\/Converting_Database_Character_Sets\" target=\"_blank\">http:\/\/codex.wordpress.org\/Converting_Database_Character_Sets<\/a> I realized that the reason the upgrade didn&#8217;t work was when I was upgrading from MySQL 4 to MySQL 5. I host with <a href=\"http:\/\/www.1and1.com\/?affiliate_id=143014\" target=\"_blank\">1and1<\/a> and used their import script to import the SQL that was exported. Unfortunately, as the exported SQL was too simple (it didn&#8217;t explicitly say the COLLATION for <b>each<\/b> field, and table) the resulting set of wordpress tables were all created with latin1_general_ci as the collation. All the automatic scripts provided by wordpress has already completed and reported success, so it&#8217;s time to go manual.<\/p>\n<p>This is what I did:<\/p>\n<p><b>1. Fix relevant field&#8217;s collation<\/b><\/p>\n<p>I switched the collation of the relevant fields (post content, post title, post name, etc. and also link and comments table) where I normally will sprinkle UTF-8 characters in from <b>latin1_general_ci<\/b> to <b>utf8_unicode_ci<\/b>. You don&#8217;t really need to know SQL much, just go to your phpMyAdmin, then the table, Structure, the little Edit pencil of the field and you can change the drop down&#8217;s value.<\/p>\n<p>You don&#8217;t have to fix every field, although the links above advises you to do so. I&#8217;m going to let this mix mode run for a while. If you&#8217;re not sure which fields to switch, then fix every text field (all the best).<\/p>\n<p><b>2. Reexport the table as UPDATE<\/b><\/p>\n<p>Next, I went back to my old MySQL 4 DB, re-exported (careful: remember to keep everything UTF-8, save the file as UTF-8) the relevant tables using the Export function. Under Data, I used the <b>UPDATE<\/b> option, as this will create UPDATE statements instead of INSERT statements (since the entries were already inserted by the wordpress upgrade.php scripts). I omitted the Structure (i.e. the CREATE TABLE statement). What you want to get is a bunch of UPDATE sql statements that has your UTF-8 characters in it saved to a UTF-8 file.<\/p>\n<p>Do take note that if you are also upgrading wordpress, some field names \/ types might change. I did a field to field comparison and found my situation to be identical. If yours isn&#8217;t, you will need to do some search and replace (or Perl script for advanced users) &#8211; just keep saving the file in UTF-8 format lest you lose them again.<\/p>\n<p><b>3. Import the table<\/b><\/p>\n<p>Next, I switched back to the new MySQL 5 DB, use the SQL function to upload the file and run it. That&#8217;s all. Sometimes uploaded files won&#8217;t work with 1and1, so I copied the file into the browser window. Mine was like 2 to 3 MB in size so it wasn&#8217;t much of a problem \/ wait.<\/p>\n<p>*phew*<\/p>\n<p>Did it 3 times for 3 tables: wp_links, wp_comments, wp_posts. <\/p>\n<p>And the site is back up!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Upgraded my WordPress and had my Chinese Characters all gone! After some inspiration from http:\/\/alexking.org\/blog\/2008\/03\/06\/mysql-latin1-utf8-conversion and http:\/\/codex.wordpress.org\/Converting_Database_Character_Sets I&#8230;<\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2],"tags":[],"class_list":["post-903","post","type-post","status-publish","format-standard","hentry","category-technology","content-wrap"],"_links":{"self":[{"href":"https:\/\/wp.jiinjoo.com\/index.php?rest_route=\/wp\/v2\/posts\/903","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/wp.jiinjoo.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/wp.jiinjoo.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/wp.jiinjoo.com\/index.php?rest_route=\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/wp.jiinjoo.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=903"}],"version-history":[{"count":2,"href":"https:\/\/wp.jiinjoo.com\/index.php?rest_route=\/wp\/v2\/posts\/903\/revisions"}],"predecessor-version":[{"id":906,"href":"https:\/\/wp.jiinjoo.com\/index.php?rest_route=\/wp\/v2\/posts\/903\/revisions\/906"}],"wp:attachment":[{"href":"https:\/\/wp.jiinjoo.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=903"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/wp.jiinjoo.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=903"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/wp.jiinjoo.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=903"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}