<?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>Web2.0 Tutorials &#187; collation</title>
	<atom:link href="http://www.zulutown.com/blog/tag/collation/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.zulutown.com/blog</link>
	<description>All the Guides You Need to Become a Web2.0 Expert</description>
	<lastBuildDate>Mon, 13 Jul 2009 07:50:00 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Migrate MySQL database from latin1 to utf8</title>
		<link>http://www.zulutown.com/blog/2009/02/04/migrate-mysql-database-from-latin1-to-utf8/</link>
		<comments>http://www.zulutown.com/blog/2009/02/04/migrate-mysql-database-from-latin1-to-utf8/#comments</comments>
		<pubDate>Wed, 04 Feb 2009 22:05:33 +0000</pubDate>
		<dc:creator>Zulutown Webmaster</dc:creator>
				<category><![CDATA[MySQL]]></category>
		<category><![CDATA[character set]]></category>
		<category><![CDATA[collation]]></category>
		<category><![CDATA[latin1]]></category>
		<category><![CDATA[utf8]]></category>

		<guid isPermaLink="false">http://www.zulutown.com/blog/?p=66</guid>
		<description><![CDATA[Unluckily it&#8217;s very common not to change the default charset of your MySQL server and, since the default is latin1, when someone wishes to store cyrillic or chinese character there are many problems.
The first step is to fix the MySQL installation in order to store internationalized information., so locate your my.cnf configuration file on Linux, [...]]]></description>
			<content:encoded><![CDATA[<p>Unluckily it&#8217;s very common not to change the default charset of your MySQL server and, since the default is <code>latin1</code>, when someone wishes to store cyrillic or chinese character there are many problems.</p>
<p>The first step is to fix the MySQL installation in order to store internationalized information., so locate your <code>my.cnf</code> configuration file on Linux, or the <code>my.ini</code> on Windows boxes.</p>
<p>Search in the configuration file the <code>[mysqld]</code> section when there is the configuration  of the MySQL server.</p>
<p>Insert the following lines and eventually remove any existing configuration option with the same name.</p>
<pre>
[mysqld]
character-set-server=utf8
default-collation=utf8_unicode_ci
</pre>
<p>The option <code>character-set-server=utf8</code> tells to the server that, if not otherwise specified, the character set of the created databases, tables, column will be <code>utf8</code>.</p>
<p><code>utf8</code> columns will be able to store cyrillic or simplified chinese character, just to give you two examples.</p>
<p>The <em>collation</em> defines how alphabetical ordering will happen, in few words which is the order of the letters that we expect on <code>ORDER BY columnName</code> clauses.</p>
<p>The suffix <code>_ci</code> means that ordering and comparison will be <em>case insensitive</em> and this is the common behavior used in databases.</p>
<p>Be very careful, because usually programming languages (i.e. <em>Java</em>) have case sensitive <code>.equals(String string)</code> method on <code>String</code> class, so it&#8217;s quite common to have some mistakes caused by this incongruency.</p>
<p>Then look for the <code>[client]</code> section of your configuration file, and write this line below it.</p>
<pre>
[client]
default-character-set=utf8
</pre>
<p>This is very important because it defines the character set used by the MySQL command-line client, and that&#8217;s what will be used to migrate the data from <code>latin1</code> to <code>utf8</code>.</p>
<p>Now everything is setup, restart MySQL to make sure it&#8217;s using the updated configuration, and shut-down any application that is using the database that&#8217;s going to be migrated.</p>
<p>First, <code>mysqldump</code> will create a <em>.sql</em> file containing all the data:</p>
<pre>mysqldump --skip-set-charset --no-create-db –no-create-info -h hostname --protocol=TCP -P 3306 -u username -p old_database &gt; dump.sql</pre>
<p>The option <code>--skip-set-charset</code> prevents that in the dump file will be any reference to the old (and wrong) character sets. The options <code>--no-create-db</code> and  <code>--no-create-info</code> are used because the new database name will be defined later.</p>
<p>Now the new database is going to be created: <code>mysql -u username -p</code> and the following SQL should be executed in the terminal:</p>
<pre>
create schema new_database;
quit
</pre>
<p>Finally the last step is to populate the brand new database with the dumped data:</p>
<pre>mysql -u username -p new_database &lt; dump.sql
</pre>
<p>In this way all the previous data from <code>old_database</code> is now stored in <em>utf8</em> format in <code>new_database</code>.</p>
<p>I hope this tutorial can be useful, please ask any question or give your feedback.<br />
Thank You.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.zulutown.com/blog/2009/02/04/migrate-mysql-database-from-latin1-to-utf8/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
	</channel>
</rss>
