<?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>Statistics, R, Graphics and Fun &#187; MySQL</title>
	<atom:link href="http://yihui.name/en/tag/mysql/feed/" rel="self" type="application/rss+xml" />
	<link>http://yihui.name/en</link>
	<description>Yihui XIE</description>
	<lastBuildDate>Fri, 23 Jul 2010 16:33:54 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Convert MySQL Database to UTF-8 in WordPress</title>
		<link>http://yihui.name/en/2009/05/convert-mysql-database-to-utf-8-in-wordpress/</link>
		<comments>http://yihui.name/en/2009/05/convert-mysql-database-to-utf-8-in-wordpress/#comments</comments>
		<pubDate>Fri, 29 May 2009 16:01:55 +0000</pubDate>
		<dc:creator>Yihui Xie</dc:creator>
				<category><![CDATA[Computer Science]]></category>
		<category><![CDATA[CHARSET]]></category>
		<category><![CDATA[COLLATION]]></category>
		<category><![CDATA[Database]]></category>
		<category><![CDATA[LIKE]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[SHOW TABLES]]></category>
		<category><![CDATA[UTF-8]]></category>
		<category><![CDATA[Wordpress]]></category>

		<guid isPermaLink="false">http://yihui.name/en/?p=212</guid>
		<description><![CDATA[his plugin is based on the post &#8220;Convert MySQL Tables to UTF-8&#8221; and an existing plugin by g30rg3_x. The reason I modified their code is that they will convert all tables in your database to the UTF-8 charset, but what we need is to convert WP tables, so I changed the code "SHOW TABLES" to [...]]]></description>
			<content:encoded><![CDATA[<a href="http://yihui.name/en/2009/05/convert-mysql-database-to-utf-8-in-wordpress/"><span class="dropcap-none">T</span></a>his plugin is based on the post &#8220;<a href="http://www.sveit.com/forum/viewtopic.php?t=1282#p11543">Convert MySQL Tables to UTF-8</a>&#8221; and an <a title="UTF-8 Database Converter" href="http://wordpress.org/extend/plugins/utf-8-database-converter/" target="_blank">existing plugin by g30rg3_x</a>. The reason I modified their code is that they will convert <em>all</em> tables in your database to the UTF-8 charset, but what we need is to convert WP tables, so I changed the code <code>"SHOW TABLES"</code> to <code>"SHOW TABLES LIKE " . $table_prefix . "%"</code>, which will guarantee other tables could stay untouched. Besides, g30rg3_x&#8217;s purpose was to alter the charset of old WP databases to new UTF-8 databases, but in fact we also need to change the charset after we moved our DB to a new host when the charset is not UTF-8 by default. Judging from my experience, the default charset/collation for many web hosts is <code>latin1</code>/<code>latin1_swedish_ci</code> (I don&#8217;t know why), whereas popular web-buidling systems often use <code>utf8</code>/<code>utf8_general_ci</code>, thus we need to change the charset before all content could be normally displayed. Without PHP and <code>SHOW TALBES</code> / <code>SHOW COLUMNS</code>, we will need to write endless code to change all tables and all columns.</p>
<pre>mysql&gt; select collation('asdf'); # default collation
+-------------------+
| collation('asdf') |
+-------------------+
| latin1_swedish_ci |
+-------------------+
1 row in set (0.00 sec)</pre>
<p><span class="download">Download the <a href="http://downloads.wordpress.org/plugin/utf-8-db-converter.zip">UTF-8 DB Converter for WordPress</a></span>
<p>The critical part of this plugin is:</p>
<pre>....
$sql2 = "ALTER TABLE $table DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci";
....
$sql4 = "ALTER TABLE $table CHANGE `$field_name` `$field_name` $field_type
         CHARACTER SET utf8 COLLATE utf8_bin";
....</pre>
<p>I don&#8217;t think I need to describe the installation again, but I sould warn you again about possible data lost during the conversion. Do back up early please.</p>
<h2  class="related_post_title">Related Posts</h2><ul class="related_post"><li><a href="http://yihui.name/en/2009/06/creating-tag-cloud-using-r-and-flash-javascript-swfobject/" title="Creating Tag Cloud Using R and Flash / JavaScript (SWFObject)">Creating Tag Cloud Using R and Flash / JavaScript (SWFObject)</a></li></ul>]]></content:encoded>
			<wfw:commentRss>http://yihui.name/en/2009/05/convert-mysql-database-to-utf-8-in-wordpress/feed/</wfw:commentRss>
		<slash:comments>19</slash:comments>
		</item>
	</channel>
</rss>
