<?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>Khaled alHabache's official blog &#187; mysql</title>
	<atom:link href="http://www.khelll.com/blog/tag/mysql/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.khelll.com/blog</link>
	<description>What web development means....</description>
	<lastBuildDate>Tue, 16 Mar 2010 23:21:41 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=abc</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Changing database encoding from latin1 to UTF8</title>
		<link>http://www.khelll.com/blog/mysql/changing-database-encoding-from-latin-to-utf8/</link>
		<comments>http://www.khelll.com/blog/mysql/changing-database-encoding-from-latin-to-utf8/#comments</comments>
		<pubDate>Fri, 05 Dec 2008 20:59:31 +0000</pubDate>
		<dc:creator>khelll</dc:creator>
				<category><![CDATA[mysql]]></category>
		<category><![CDATA[arabic]]></category>
		<category><![CDATA[utf8]]></category>

		<guid isPermaLink="false">http://www.khelll.com/blog/?p=46</guid>
		<description><![CDATA[Now a days, UTF-8 is the most used data encoding format, and the fact that your database is not using UTF8 encoding is really annoying, specially additionally when it comes to integrating different systems, that has no one unified encoding format.
So if you think it&#8217;s time to change your data encoding to utf8 format, then [...]]]></description>
			<content:encoded><![CDATA[<p>Now a days, <a href="http://en.wikipedia.org/wiki/UTF-8">UTF-8</a> is the most used data encoding format, and the fact that your database is not using UTF8 encoding is really annoying, specially additionally when it comes to integrating different systems, that has no one unified encoding format.<br />
So if you think it&#8217;s time to change your data encoding to utf8 format, then here what this post is all about.<br />
I&#8217;ll list here the steps to do so, i just have to clarify that the main data encoding here is windows-1256 (which is the main Arabic encoding used in web applications), but it&#8217;s saved in latin1 encoding in the database (mydata ->windows-1256 -> latin1) ,also note that i&#8217;m  using Mysql database.<br />
Here are the steps:</p>
<ol>
<li>Export (only) the schema of the db,without &#8220;set Names&#8221; phrase in the outputted sql file, this will bring you back the data in the original encoding (windows-1256)

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">mysqldump <span style="color: #660033;">--default-character-set</span>=latin1 <span style="color: #660033;">--skip-set-charset</span> <span style="color: #660033;">-d</span> <span style="color: #660033;">-uusername</span> <span style="color: #660033;">-ppassword</span> db_name <span style="color: #000000; font-weight: bold;">&gt;</span> db_name_schema.sql</pre></div></div>

</li>
<li>Export the data of the db without &#8220;set Names&#8221; phrase in the outputted sql file, this will bring you back the data in the original encoding (windows-1256):

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">mysqldump <span style="color: #660033;">--default-character-set</span>=latin1 <span style="color: #660033;">--skip-set-charset</span> <span style="color: #660033;">-t</span> <span style="color: #660033;">-uusername</span> <span style="color: #660033;">-ppassword</span>  db_name <span style="color: #000000; font-weight: bold;">&gt;</span> db_name_data.sql</pre></div></div>

</li>
<li>Change the encoding of both files from arabic to utf8 -check the notes if you r using windows

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">iconv <span style="color: #660033;">-f</span> windows-<span style="color: #000000;">1256</span> <span style="color: #660033;">-t</span> utf8 db_name_schema.sql <span style="color: #000000; font-weight: bold;">&gt;</span> db_name_schema_utf8.sql
iconv <span style="color: #660033;">-f</span> windows-<span style="color: #000000;">1256</span> <span style="color: #660033;">-t</span> utf8 db_name_data.sql <span style="color: #000000; font-weight: bold;">&gt;</span> db_name_data_utf8.sql</pre></div></div>

</li>
<li> Open the file &#8216;db_name_schema.sql&#8217; with any editor and replace each &#8220;DEFAULT CHARSET=latin1&#8243; phrase with &#8220;DEFAULT CHARSET=utf8&#8243; one
</li>
<li>Make a new db ,encoded in utf8:

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"> mysql <span style="color: #660033;">-uusername</span> <span style="color: #660033;">-ppassword</span> <span style="color: #660033;">-e</span> <span style="color: #ff0000;">'CREATE DATABASE new_db DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci'</span></pre></div></div>

</li>
<li>Import the schema and data in utf8 encoding:

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">mysql <span style="color: #660033;">--default-character-set</span>=utf8 <span style="color: #660033;">-uusername</span> <span style="color: #660033;">-ppassword</span> new_db <span style="color: #000000; font-weight: bold;">&lt;</span> db_name_schema_utf8.sql
mysql <span style="color: #660033;">--default-character-set</span>=utf8  <span style="color: #660033;">-uusername</span> <span style="color: #660033;">-ppassword</span> new_db <span style="color: #000000; font-weight: bold;">&lt;</span> db_name_data_utf8.sql</pre></div></div>

</li>
</ol>
<p><strong> notes</strong></p>
<ul>
<li class="level1">
<div class="li">If you are wondering why to separate schema from data upon exporting , then the answer is that the operation of replacing &#8220;DEFAULT CHARSET=latin1&#8243; phrase with &#8220;DEFAULT CHARSET=utf8&#8243; one , is taking place only on schema files, so it&#8217;s recommended to separate them so that you dont stuck when loading the big data files.</div>
</li>
<li class="level1">
<div class="li">If you are a windows user and can&#8217;t use iconv , then u can use any editor to do the job for u, try scite or note++ or even dreamweaver</div>
</li>
</ul>
<p>enjoy!!!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.khelll.com/blog/mysql/changing-database-encoding-from-latin-to-utf8/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
	</channel>
</rss>
