{"id":64,"date":"2010-01-11T15:53:36","date_gmt":"2010-01-11T20:53:36","guid":{"rendered":"http:\/\/blogs.law.harvard.edu\/djcp\/?p=64"},"modified":"2010-01-11T16:01:10","modified_gmt":"2010-01-11T21:01:10","slug":"convert-mysql-database-from-latin1-to-utf8-the-right-way","status":"publish","type":"post","link":"https:\/\/archive.blogs.harvard.edu\/djcp\/2010\/01\/convert-mysql-database-from-latin1-to-utf8-the-right-way\/","title":{"rendered":"Convert mysql database from latin1 to utf8 the RIGHT way"},"content":{"rendered":"<p>You&#8217;ll see many blog posts around the interwebs stating that you can just dump a mysql database via mysqldump &#8211; globally replace &#8220;latin1&#8221; (or some other character set) in the dump file &#8211; and then import that into a utf8 database and it&#8217;ll just work. This appears, however, to be WRONG. It does not force mysql to convert the text, it only fools you into believing that that your latin1 characters have been converted.  You have to actually convert the text yourself, the columns will just be unconverted latin1 sitting in a utf8 table.<\/p>\n<p>One way to do this is to convert the column in question to binary and back again &#8211; assuming your database\/table is set to utf8, this will force MySQL to convert the character set correctly.<\/p>\n<p>Another &#8211; better  &#8211; way is to just use iconv to convert during the dump process.  This will convert latin1 characters to utf8 properly.<\/p>\n<p><code>mysqldump --add-drop-table database_to_correct  | replace CHARSET=latin1 CHARSET=utf8 | iconv -f latin1 -t utf8 | mysql database_to_correct<\/code><\/p>\n<p>PLEASE correct me if I&#8217;m wrong &#8211; this seems like yet another mysql idiosyncrasy that shouldn&#8217;t exist.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>You&#8217;ll see many blog posts around the interwebs stating that you can just dump a mysql database via mysqldump &#8211; globally replace &#8220;latin1&#8221; (or some other character set) in the dump file &#8211; and then import that into a utf8 &hellip; <a href=\"https:\/\/archive.blogs.harvard.edu\/djcp\/2010\/01\/convert-mysql-database-from-latin1-to-utf8-the-right-way\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1984,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-64","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/archive.blogs.harvard.edu\/djcp\/wp-json\/wp\/v2\/posts\/64","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/archive.blogs.harvard.edu\/djcp\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/archive.blogs.harvard.edu\/djcp\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/archive.blogs.harvard.edu\/djcp\/wp-json\/wp\/v2\/users\/1984"}],"replies":[{"embeddable":true,"href":"https:\/\/archive.blogs.harvard.edu\/djcp\/wp-json\/wp\/v2\/comments?post=64"}],"version-history":[{"count":4,"href":"https:\/\/archive.blogs.harvard.edu\/djcp\/wp-json\/wp\/v2\/posts\/64\/revisions"}],"predecessor-version":[{"id":68,"href":"https:\/\/archive.blogs.harvard.edu\/djcp\/wp-json\/wp\/v2\/posts\/64\/revisions\/68"}],"wp:attachment":[{"href":"https:\/\/archive.blogs.harvard.edu\/djcp\/wp-json\/wp\/v2\/media?parent=64"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/archive.blogs.harvard.edu\/djcp\/wp-json\/wp\/v2\/categories?post=64"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/archive.blogs.harvard.edu\/djcp\/wp-json\/wp\/v2\/tags?post=64"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}