<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet href="/stylesheets/rss.css" type="text/css"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/">
  <channel>
    <title>Dev411 Blog: Perl, MySQL and UTF-8</title>
    <link>http://www.dev411.com/blog/2006/10/02/perl-mysql-and-utf-8</link>
    <language>en-us</language>
    <ttl>40</ttl>
    <description>John Wang on Technology</description>
    <item>
      <title>Perl, MySQL and UTF-8</title>
      <description>&lt;p&gt;One of the mysteries of Perl to me is that why, as of yet, is there no UTF-8 support in DBD::mysql although this issue has been discussed on the msql-mysql-modules list since at least 2003 (using the MARC archives). This is also given that MySQL does have UTF-8 support itself.&lt;/p&gt;

&lt;p&gt;When I first looked into this I found a few articles on this:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="http://www.simplicidade.org/notes/archives/2005/12/utf8_and_dbdmys.html"&gt;utf-8 and DBD::mysql by Pedro Melo&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://www.zackvision.com/weblog/2005/11/mt-unicode-mysql.html"&gt;Movable Type, MySQL, Perl, Unicode by Zakaria "Zack" Ajmal: provides a patch for Movable Type 3.2&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Pedro's article mentions that the reason this hasn't been done for DBD::mysql is that the DBI and DBD::mysql folks cannot decide where to put UTF-8 implementation, i.e. in DBI itself or the DBD drivers. Because, there is still no built-in support. To get around this, there have been numerous patches produced. Andrew Forrest even put together UTF-8 versions of DBI and CGI.pm (link seems broken atm). However, some of these patches seem to have problems and are non-standard.&lt;/p&gt;

&lt;p&gt;If you prefer to use an ORM, DBIx::Class and Class::DBI get around this by implementing UTF-8 support in their own libraries with DBIx::Class::UTF8Columns and Class::DBI::utf8 respectively. I'd recommend DBIx::Class over Class::DBI since it has more functionality (e.g. built-in JOIN support) and is supposed to generate more efficient SQL.&lt;/p&gt;

&lt;p&gt;The intersting thing is that DBD::Pg for PostgreSQL has had built-in UTF-8 support for some time. While not an issue specific to the MySQL database, the UTF-8 perl driver issue is something to consider when choosing MySQL or PostgreSQL.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Update:&lt;/strong&gt; Thanks to Dominic Mitchell for mentioning the latest developer release, &lt;a href="http://search.cpan.org/~capttofu/DBD-mysql-3.0007_1/"&gt;DBD::mysql 3.0007_1&lt;/a&gt; released on 8 Sep 2006, has integrated UTF-8 support. It's a developer release but good things are finally happening!&lt;/p&gt;</description>
      <pubDate>Mon, 02 Oct 2006 10:35:00 -0500</pubDate>
      <guid isPermaLink="false">urn:uuid:559515eb-db34-4760-832f-3b103e81fc08</guid>
      <author>John Wang</author>
      <link>http://www.dev411.com/blog/2006/10/02/perl-mysql-and-utf-8</link>
      <category>perl</category>
      <category>mysql</category>
      <category>unicode</category>
      <category>orm</category>
    </item>
    <item>
      <title>"Perl, MySQL and UTF-8" by admin</title>
      <description>&lt;p&gt;mysql&#30340;&#20248;&#21270;&lt;/p&gt;</description>
      <pubDate>Sat, 24 Nov 2007 12:25:18 -0600</pubDate>
      <guid isPermaLink="false">urn:uuid:60570998-dfdd-47b8-9671-f0b98f7ec2f9</guid>
      <link>http://www.dev411.com/blog/2006/10/02/perl-mysql-and-utf-8#comment-219</link>
    </item>
    <item>
      <title>"Perl, MySQL and UTF-8" by Artem Russakovskii</title>
      <description>&lt;p&gt;In case you need utf8 support in DBD::mysql before the aforementioned 3.007 release, you can use&lt;/p&gt;


	&lt;p&gt;$dbh-&amp;gt;do(&amp;#8220;SET NAMES &amp;#8216;utf8&amp;#8217;&amp;#8221;);&lt;/p&gt;


	&lt;p&gt;after getting the db handle.&lt;/p&gt;</description>
      <pubDate>Wed, 14 Nov 2007 23:44:53 -0600</pubDate>
      <guid isPermaLink="false">urn:uuid:fee34935-cfb0-4b98-860f-c46ae8635a92</guid>
      <link>http://www.dev411.com/blog/2006/10/02/perl-mysql-and-utf-8#comment-217</link>
    </item>
    <item>
      <title>"Perl, MySQL and UTF-8" by John Wang</title>
      <description>&lt;p&gt;Robbie: I think you misread the article since it says &amp;#8220;MySQL does have UTF-8 support&amp;#8221; with the issue being UTF-8 support in the DBD::mysql driver, not the MySQL database.&lt;/p&gt;</description>
      <pubDate>Thu, 05 Oct 2006 09:38:21 -0500</pubDate>
      <guid isPermaLink="false">urn:uuid:b4199021-2774-4d75-bd13-a947b503e703</guid>
      <link>http://www.dev411.com/blog/2006/10/02/perl-mysql-and-utf-8#comment-131</link>
    </item>
    <item>
      <title>"Perl, MySQL and UTF-8" by Robbie Bow</title>
      <description>&lt;p&gt;Just a small correction: MySQL 5.0 does have UTF8 support. I&amp;#8217;m not sure, but I think 4.1 also does.&lt;/p&gt;</description>
      <pubDate>Thu, 05 Oct 2006 04:47:32 -0500</pubDate>
      <guid isPermaLink="false">urn:uuid:4ec414d9-7b9a-486f-bd51-e8f66d527f40</guid>
      <link>http://www.dev411.com/blog/2006/10/02/perl-mysql-and-utf-8#comment-130</link>
    </item>
    <item>
      <title>"Perl, MySQL and UTF-8" by John Wang</title>
      <description>&lt;p&gt;Wow, that&amp;#8217;s exciting news! Thanks for posting about the developer release. Looks like I may try it out soon.&lt;/p&gt;</description>
      <pubDate>Mon, 02 Oct 2006 15:19:49 -0500</pubDate>
      <guid isPermaLink="false">urn:uuid:98c0c283-602b-41d6-a93d-4209ad28cecf</guid>
      <link>http://www.dev411.com/blog/2006/10/02/perl-mysql-and-utf-8#comment-126</link>
    </item>
    <item>
      <title>"Perl, MySQL and UTF-8" by Dominic Mitchell</title>
      <description>&lt;p&gt;Wait no longer!  &lt;a href="http://search.cpan.org/~capttofu/DBD-mysql-3.0007_1/" rel="nofollow"&gt;DBD::mysql 3.007_01&lt;/a&gt; has now got the same level of utf8 support as DBD::Pg.  I sent the patch to Patrick Galbraith and it got in!  That version is lacking tests, but they should be in the next version.&lt;/p&gt;


	&lt;p&gt;It&amp;#8217;s basically the same idea as in DBD::Pg.  You set &lt;code&gt;$dbh-&amp;gt;{mysql_enable_utf8}&lt;/code&gt; and any text columns come back as UTF8 if they&amp;#8217;re valid.&lt;/p&gt;


	&lt;p&gt;I also managed to get the support into DBD::Pg a couple of years back.  This was quite lucky as the patches are very similar.  &lt;code&gt;:-)&lt;/code&gt;&lt;/p&gt;</description>
      <pubDate>Mon, 02 Oct 2006 14:56:09 -0500</pubDate>
      <guid isPermaLink="false">urn:uuid:5f56af2e-ae44-4b5c-abf4-18c223f86b02</guid>
      <link>http://www.dev411.com/blog/2006/10/02/perl-mysql-and-utf-8#comment-125</link>
    </item>
  </channel>
</rss>
