{"id":219,"date":"2007-07-10T08:50:24","date_gmt":"2007-07-10T08:50:24","guid":{"rendered":"http:\/\/dev.gregbueno.com\/wp\/sakufu\/2007\/07\/10\/what_i_learned_2\/"},"modified":"2007-07-10T08:50:24","modified_gmt":"2007-07-10T08:50:24","slug":"what_i_learned_2","status":"publish","type":"post","link":"https:\/\/gregbueno.com\/sakufu\/2007\/07\/10\/what_i_learned_2\/","title":{"rendered":"What I learned: &#8216;Set Names utf8&#8217; is your friend"},"content":{"rendered":"<p>I knew at some point, given the amount of Japanese interspersed with English on my various sites, I would need to change the Latin-1 encoding of my MySQL database (say that five times fast) to UTF-8. It hasn&#8217;t been much of an issue because when I display that text on a web site, I send UTF-8 encoding in the header.<\/p>\n<p>I reached a breaking point when with trying to sort a text field with mixed languages. Because the database was encoded in Latin-1, the multibyte strings were sorted as single-byte strings. On a web page, that meant Japanese text would appear in the middle of the sort.<\/p>\n<p>Well, I finally did a <a href=\"http:\/\/www.google.com\/search?hl=en&amp;q=mysql+convert+latin1+utf8&amp;btnG=Google+Search\">Google search<\/a> on what it takes to perform a <a href=\"http:\/\/tlug.dnho.net\/?q=node\/276\">Latin-1-to-UTF-8 conversion<\/a>. So long as your data is fairly clean, it takes about four commands in a shell prompt to finish. And that&#8217;s what I did &#8212; I dumped my database, converted it and loaded it into an empty server to see the results. I liked what I saw in phpMyAdmin. Hastily, I decided to forge ahead and do a real conversion.<\/p>\n<p>Imagine my surprise when I reloaded my websites and saw question marks where there should have been Japanese text.<\/p>\n<p><!--more--><\/p>\n<p>After a failed attempt to roll back my database, I did a bit more searching and discovered I needed to send a &quot;Set Names utf8&quot; query to the MySQL server before performing any other queries. Thankfully, that was just a single line to add in my self-written toolkit, which powers this site and others.<\/p>\n<p>That wasn&#8217;t the case with Movable Type, however. The question marks showed up in the administration interface. A <a href=\"http:\/\/www.google.com\/search?hl=en&amp;q=movable+type+utf8+mysql+question+marks&amp;btnG=Google+Search\">bit more searching<\/a> revealed the &quot;<a href=\"http:\/\/www.sixapart.com\/movabletype\/docs\/3.3\/d_configuration_directives\/sqlsetnames.html\">SQLSetNames 1<\/a>&quot; configuration value in <code>mt-config.cgi<\/code>. Question marks gone.<\/p>\n<p>Had I been diligent, I would have done some work in my development environment before going half-cocked into a database conversion. Instead, I ended up panicking for a full hour trying to get my sites fixed. At the end of it, I was quite pleased when I saw Japanese text sorted separately from English.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Imagine my surprise when I reloaded my websites and saw question marks where there should have been Japanese text.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[6],"tags":[],"class_list":["post-219","post","type-post","status-publish","format-standard","hentry","category-technophilia-professional"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p4Bkjq-3x","_links":{"self":[{"href":"https:\/\/gregbueno.com\/sakufu\/wp-json\/wp\/v2\/posts\/219","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/gregbueno.com\/sakufu\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/gregbueno.com\/sakufu\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/gregbueno.com\/sakufu\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/gregbueno.com\/sakufu\/wp-json\/wp\/v2\/comments?post=219"}],"version-history":[{"count":0,"href":"https:\/\/gregbueno.com\/sakufu\/wp-json\/wp\/v2\/posts\/219\/revisions"}],"wp:attachment":[{"href":"https:\/\/gregbueno.com\/sakufu\/wp-json\/wp\/v2\/media?parent=219"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/gregbueno.com\/sakufu\/wp-json\/wp\/v2\/categories?post=219"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/gregbueno.com\/sakufu\/wp-json\/wp\/v2\/tags?post=219"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}