<?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>labs.leftcolumn.net &#187; collation</title>
	<atom:link href="http://labs.leftcolumn.net/tag/collation/feed/" rel="self" type="application/rss+xml" />
	<link>http://labs.leftcolumn.net</link>
	<description>Web Development from stem to stern</description>
	<lastBuildDate>Sat, 30 Jan 2010 20:06:52 +0000</lastBuildDate>
	
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>How to prevent weird characters after MySQL export and import</title>
		<link>http://labs.leftcolumn.net/2009/09/how-to-prevent-weird-characters-after-mysql-export-and-import/</link>
		<comments>http://labs.leftcolumn.net/2009/09/how-to-prevent-weird-characters-after-mysql-export-and-import/#comments</comments>
		<pubDate>Sat, 26 Sep 2009 03:53:01 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[MySQL]]></category>
		<category><![CDATA[collation]]></category>
		<category><![CDATA[how to]]></category>

		<guid isPermaLink="false">http://labs.leftcolumn.net/?p=4</guid>
		<description><![CDATA[When you export from a MySQL Database to a .sql file, then import that into a new Database, you may find a bunch of weird characters. This post is not an exhaustive explanation of why the problem happens, more a note on how to avoid the issue when exporting and importing in MySQL.
The issue is [...]]]></description>
			<content:encoded><![CDATA[<p>When you export from a MySQL Database to a .sql file, then import that into a new Database, you may find a bunch of weird characters. This post is not an exhaustive explanation of why the problem happens, more a note on how to avoid the issue when exporting and importing in MySQL.</p>
<p>The issue is essentially tied up with a mismatch between default collation in MySQL and the collation / character sets specified in the .sql file. To fix the issue, make sure they all match. If you&#8217;re using MySQL 4+, the default collation is probably UTF-8, so just make sure that the file has a default colltion set too. Putting the following line at the top of the .sql seems to do the trick:</p>
<div class="codecolorer-container text twitlight" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">/*!40101 SET NAMES utf8 */;</div></div>
<p>The reason seems to be with the importer: even though there is a default collation set on the database and on the tables, if there&#8217;s no default for the whole file each insert gets misinterpreted as a UTF-8 table that must be encapsulated in as latin1.  Also check that the table creation statements in the .sql file are UTF-8 too, like this:</p>
<div class="codecolorer-container text twitlight" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">CREATE TABLE `wp_comments` (<br />
...<br />
) ENGINE=MyISAM &nbsp;DEFAULT CHARSET=utf8;</div></div>
<p>For more detailed information, and info on how to fix existing databases, check out <a href="http://www.orthogonalthought.com/blog/index.php/2007/05/mysql-database-migration-and-special-characters/">http://www.orthogonalthought.com/blog/index.php/2007/05/mysql-database-migration-and-special-characters/</a>. There is a <a href="http://wordpress.org/extend/plugins/bbwp2utf8/">plugin for Wordpress that will convert the database</a>, but this didn&#8217;t work for me.</p>
]]></content:encoded>
			<wfw:commentRss>http://labs.leftcolumn.net/2009/09/how-to-prevent-weird-characters-after-mysql-export-and-import/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

