<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Space Babies &#187; mysql</title>
	<atom:link href="http://www.spacebabies.nl/category/mysql/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.spacebabies.nl</link>
	<description>extraterrestrialicious web apps</description>
	<lastBuildDate>Wed, 18 Jan 2012 21:52:06 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3</generator>
		<item>
		<title>Fixing MySQL encoding issues with Ruby 1.9.2</title>
		<link>http://www.spacebabies.nl/2010/12/23/fixing-mysql-encoding-issues-with-ruby-1-9-2/</link>
		<comments>http://www.spacebabies.nl/2010/12/23/fixing-mysql-encoding-issues-with-ruby-1-9-2/#comments</comments>
		<pubDate>Thu, 23 Dec 2010 13:53:46 +0000</pubDate>
		<dc:creator>joost</dc:creator>
				<category><![CDATA[mysql]]></category>
		<category><![CDATA[rants]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[tech]]></category>

		<guid isPermaLink="false">http://www.spacebabies.nl/?p=1686</guid>
		<description><![CDATA[There have been tens, hundreds, thousands blogs posts related to Latin1/UTF8 encoding issues. So here is yet another, this time related to upgrading from Ruby 1.8.6 + mysql gem to Ruby 1.9.2 + mysql2 gem.Here&#8217;s the thing: ever since Rails &#8230; <a href="http://www.spacebabies.nl/2010/12/23/fixing-mysql-encoding-issues-with-ruby-1-9-2/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>There have been tens, hundreds, thousands blogs posts related to Latin1/UTF8 encoding issues. So here is yet another, this time related to upgrading from Ruby 1.8.6 + mysql gem to Ruby 1.9.2 + mysql2 gem.<span id="more-1686"></span>Here&#8217;s the thing: ever since Rails 2.1 I was under the assumption that all strings in my app were UTF-8 throughout. Wrong. Depending on your database settings, HTML HEAD, database driver and Ruby version you might will have a mix of character sets. Jay!</p>
<p>A recent upgrade of <a href="http://www.zappelin.nl/">www.zappelin.nl</a> brought this to light:</p>
<ol>
<li>utf-8 present in HTML HEAD;</li>
<li>generated Rails app with all utf-8 defaults present;</li>
<li>mysql database still had latin1 as default character set;</li>
<li>same for the table;</li>
<li>using the old mysql driver gem.</li>
</ol>
<p>The above combination led to strings still being stored as latin1 in the database.</p>
<p>MySQL documentation mentions charset conversions using ALTER TABLE. These did not work &#8212; the offending characters remained in their original character set. In the MySQL console these were printed fine: for instance ë was visible in the correct places. However in the Ruby world this was displayed as Ã«. Wuh?</p>
<p>I briefly considered dropping down to unix and using iconv on the database dump.</p>
<p>Luckily I was just too lazy today. Turns out you can convert the offending column to BLOB first and then to the correct character set. This worked! So if you have this problem the query below might fix things.</p>
<blockquote><p>ALTER TABLE tbl_name MODIFY col1 BLOB;</p>
<p>ALTER TABLE tbl_name MODIFY col1 VARCHAR(255) CHARACTER SET utf8;</p></blockquote>
<p>However, it still needed a bit of magic with regards to the default charset on the table. My best combination was to first convert the entire table to use latin1 by default, then run the conversion, then set the default to utf8. However, this didn&#8217;t work always.</p>
<blockquote><p>ALTER TABLE tbl_name CONVERT TO CHARACTER SET latin1;</p></blockquote>
<p>Keep in mind to always use the <a href="https://github.com/brianmario/mysql2">mysql2</a> gem when running under Ruby 1.9.2. Anything else is rubbish since this will not know how to deal with UTF-8 and you app will break and you will cry.</p>
<p>My wish for 2011: a definitive end to character set issues plz. This really is no fun.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.spacebabies.nl/2010/12/23/fixing-mysql-encoding-issues-with-ruby-1-9-2/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>More utf-8 woes</title>
		<link>http://www.spacebabies.nl/2007/02/20/more-utf-8-woes/</link>
		<comments>http://www.spacebabies.nl/2007/02/20/more-utf-8-woes/#comments</comments>
		<pubDate>Tue, 20 Feb 2007 17:29:53 +0000</pubDate>
		<dc:creator>joost</dc:creator>
				<category><![CDATA[mysql]]></category>

		<guid isPermaLink="false">http://www.spacebabies.nl/blog/2007/02/20/more-utf-8-woes/</guid>
		<description><![CDATA[The second installment of the utf-8 saga I started last week. Of course, per all the advice that&#8217;s out there, I needed to run some nasty-ass updates directly in MySQL. Buh. Even in my utf-8 Terminal.app I could not display &#8230; <a href="http://www.spacebabies.nl/2007/02/20/more-utf-8-woes/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>The second installment of the utf-8 saga I started last week.</p>
<p>Of course, per all the advice that&#8217;s out there, I needed to<br />
run some nasty-ass updates directly in MySQL. Buh. Even in my utf-8 Terminal.app I could not display some weirdness properly. So it came down to hex() and unhex()&#8217;ing in MySQL. Joy!</p>
<p>Even if it&#8217;s only for myself, here is the code that was used:</p>
<p><code>update articles set body = replace(body, unhex('C3A23F3F'), "'") where body regexp unhex('C3A2');</code></p>
<p>and let&#8217;s not forget this beauty:</p>
<p><code>update articles set body = replace(body, unhex('C3A23FC29D'), "'") where body regexp unhex('C3A2');</code></p>
<p>both of which returned various combinations of ??? â?? and Japanese characters to a simple apostrophe.</p>
<p>And no, the character_set_server still isn&#8217;t utf-8. Most data is fine now though.</p>
<p><span id="more-16"></span> The best part was when the regexp engine of MySQL encountered the actual question marks as a result of the unhexing. This threw all parsing down the drain, since question marks need to be escaped in a regexp. But &#8230; as you&#8217;d have guessed &#8230; those weren&#8217;t actual question marks in the database. Just the same bit combinations. Double joy!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.spacebabies.nl/2007/02/20/more-utf-8-woes/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

