<?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>Saiweb &#187; iconv</title>
	<atom:link href="http://www.saiweb.co.uk/tag/iconv/feed" rel="self" type="application/rss+xml" />
	<link>http://www.saiweb.co.uk</link>
	<description>Ramblings of a Sys admin</description>
	<lastBuildDate>Mon, 06 Feb 2012 14:57:49 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Sysamin &#8211; iconv update</title>
		<link>http://www.saiweb.co.uk/linux/sysamin-iconv-update</link>
		<comments>http://www.saiweb.co.uk/linux/sysamin-iconv-update#comments</comments>
		<pubDate>Thu, 10 Sep 2009 10:40:59 +0000</pubDate>
		<dc:creator>Buzz</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[BOM]]></category>
		<category><![CDATA[charset]]></category>
		<category><![CDATA[conversion]]></category>
		<category><![CDATA[iconv]]></category>
		<category><![CDATA[python]]></category>

		<guid isPermaLink="false">http://www.saiweb.co.uk/?p=777</guid>
		<description><![CDATA[I had a major issue facing the iconv functionality of the sysadmin toolset namely due to rushed coding. When loading a file to be re-encoded the entire file was loaded into the buffer, encoded as whole and written out to the new file, this of course meant the  memory usage was roughly double the size [...]]]></description>
			<content:encoded><![CDATA[<p>I had a major issue facing the iconv functionality of the <a href="http://www.saiweb.co.uk/sysadmin">sysadmin toolset</a> namely due to rushed coding.</p>
<p>When loading a file to be re-encoded the entire file was loaded into the buffer, encoded as whole and written out to the new file, this of course meant the  memory usage was roughly double the size of the file to be converted plus any overheads to do with the encoding itself.</p>
<p>Today I had need to convert a 1.3GB sql file, needles to say the script was crashing out with a memory error.</p>
<p>As such I have now completely re-written the function it now processes the file in 1kb &#8216;chunks&#8217;, moving the load to the CPU, this process is now very cpu intensive the the memory overhead is minimal (during test processed the 1.3GB file using 113kb of memory!!!).</p>
<p><div id="saiweb_56f917878daab654354e2fb57e99920e" style="width:487px; height:417px;"></div><script language="Javascript" type="text/javascript">
	WPFP(document).ready(function() {
		//load player
		$f("saiweb_56f917878daab654354e2fb57e99920e", "/wp-content/plugins/wordpress-flowplayer/flowplayer/gpl/flowplayer-3.1.5.swf", {
				plugins: {
  					 controls: {    					
      					
      					
      					
      					sliderGradient: 'none',
      					progressGradient: 'medium',
      					
      					
      					backgroundColor: '#141648',
      					
      					
      					backgroundGradient: 'none',
      					bufferGradient: 'none',
   						opacity:1.0
   						}
				},
			clip: {
					url:'http://cdn.saiweb.co.uk/wp-content/uploads/2009/09/sysadmin-iconv.mp4',
					autoPlay: false,
       				autoBuffering: false
				},
				canvas: {
					backgroundColor:''
				}})
			});</script>
				</p>
<p>Also I have now added BOM (Byte order mark) detection:</p>
<p><div id="saiweb_4432ff9baa147abdd85bb77451148681" style="width:515px; height:473px;"></div><script language="Javascript" type="text/javascript">
	WPFP(document).ready(function() {
		//load player
		$f("saiweb_4432ff9baa147abdd85bb77451148681", "/wp-content/plugins/wordpress-flowplayer/flowplayer/gpl/flowplayer-3.1.5.swf", {
				plugins: {
  					 controls: {    					
      					
      					
      					
      					sliderGradient: 'none',
      					progressGradient: 'medium',
      					
      					
      					backgroundColor: '#141648',
      					
      					
      					backgroundGradient: 'none',
      					bufferGradient: 'none',
   						opacity:1.0
   						}
				},
			clip: {
					url:'http://cdn.saiweb.co.uk/wp-content/uploads/2009/09/sysadmin_oconv_bom.mp4',
					autoPlay: false,
       				autoBuffering: false
				},
				canvas: {
					backgroundColor:''
				}})
			});</script>
				<span style="float: left;" ><a class="twitter-share-button"  data-via="Saiweb" data-count="horizontal" data-related="Saiweb:David Busby" data-lang="en" data-url="http://www.saiweb.co.uk/linux/sysamin-iconv-update" data-text="Sysamin &#8211; iconv update" href="http://twitter.com/share?via=Saiweb&#038;count=horizontal&#038;related=Saiweb%3ADavid%20Busby&#038;lang=en&#038;url=http%3A%2F%2Fwww.saiweb.co.uk%2Flinux%2Fsysamin-iconv-update&#038;text=Sysamin%20%26%238211%3B%20iconv%20update" >Tweet</a></span></p>
]]></content:encoded>
			<wfw:commentRss>http://www.saiweb.co.uk/linux/sysamin-iconv-update/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Converting mySQL latin1 to utf8</title>
		<link>http://www.saiweb.co.uk/mysql/converting-mysql-latin1-to-utf8</link>
		<comments>http://www.saiweb.co.uk/mysql/converting-mysql-latin1-to-utf8#comments</comments>
		<pubDate>Tue, 14 Jul 2009 08:46:02 +0000</pubDate>
		<dc:creator>Buzz</dc:creator>
				<category><![CDATA[mySQL]]></category>
		<category><![CDATA[convert]]></category>
		<category><![CDATA[converting]]></category>
		<category><![CDATA[iconv]]></category>
		<category><![CDATA[latin-1]]></category>
		<category><![CDATA[latin1]]></category>
		<category><![CDATA[multibyte]]></category>
		<category><![CDATA[mysqldump]]></category>
		<category><![CDATA[sysadmin]]></category>
		<category><![CDATA[utf-8]]></category>
		<category><![CDATA[utf8]]></category>

		<guid isPermaLink="false">http://www.saiweb.co.uk/?p=696</guid>
		<description><![CDATA[The problem We&#8217;ve all been in this position at some point, working for a company who wants to internationalize their website, and so their mySQL CMS data &#8230; But all is not so well as just using &#8216;SET NAMES utf8&#8242; and changing all &#8216;charset&#8217; on tables to utf8, You may fall foul of seeing content [...]]]></description>
			<content:encoded><![CDATA[<ul>
<strong>The problem</strong></ul>
<p>We&#8217;ve all been in this position at some point, working for a company who wants to internationalize their website, and so their mySQL CMS data &#8230;</p>
<p>But all is not so well as just using &#8216;SET NAMES utf8&#8242; and changing all &#8216;charset&#8217; on tables to utf8,</p>
<p>You may fall foul of seeing content like &#193;&pound;</p>
<p>This is due to the fact in this case the latin1 encoded £ has not properly been converted to utf8 and as such is not rendering correctly, this is true of most &#8216;multibyte&#8217; characters.</p>
<ul>
<strong>The solution</strong></ul>
<p>What you need to do is actually convert the character set to utf8, in order to do this your going to need to run it through a program you could use iconv if you are already familiar with it, however if your system has python installed you can grab a copy of my <a href="http://www.saiweb.co.uk/sysadmin">sysadmin</a> program which has iconv like functionality but is far more user friendly.</p>
<ul>
<strong>What you will need</strong></ul>
<ul>
<li>Text Editor (vi/nano/pico/emacs)</li>
<li>Python 2.4 or higher</li>
<li><a href="http://linux.about.com/od/commands/l/blcmdl1_sed.htm">SED</a> package</li>
<li><a href="http://www.saiweb.co.uk/sysadmin">Sysadmin program</a></li>
<li>mySQL</li>
</ul>
<ul>
<strong>Preparing the file</strong></ul>
<p>This assumes the database is currently using latin1, in theory this could be any encoding.</p>
<p>Get a dump of the database:</p>
<div class="codecolorer-container bash default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br /></div></td><td><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">mysqldump <span style="color: #660033;">--set-character-set</span>=latin-<span style="color: #000000;">1</span> <span style="color: #660033;">--set-charset</span> <span style="color: #660033;">-u</span> user <span style="color: #660033;">-pPASSWORD</span> databasename <span style="color: #000000; font-weight: bold;">&gt;</span> databasename-latin1.sql</div></td></tr></tbody></table></div>
<p>Now you have to be aware of what you need to replace using SED, you can&#8217;t just replace all instances of &#8216;latin1&#8242; as <a href="http://en.wikipedia.org/wiki/Murphy%27s_law">Murphy&#8217;s law</a> being as it is means that somewhere there will be &#8216;latin1&#8242; in the physical content, especially for instance if I was using a mysql dump from this blog.</p>
<p>As such you need to replace the following:</p>
<div class="codecolorer-container bash default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br /></div></td><td><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">/*!</span><span style="color: #000000;">40101</span> SET NAMES latin1 <span style="color: #000000; font-weight: bold;">*/</span>;</div></td></tr></tbody></table></div>
<p>If your database dump is small enough (sub 100mb) you can edit this line directly in your text editor, alternatively you can do the following.</p>
<div class="codecolorer-container bash default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br /></div></td><td><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #c20cb9; font-weight: bold;">cat</span> .<span style="color: #000000; font-weight: bold;">/</span>databasename-latin1.sql <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">sed</span> <span style="color: #ff0000;">'s/SET NAMES latin1/SET NAMES utf8/g'</span> <span style="color: #000000; font-weight: bold;">&gt;</span> tmp<br />
<span style="color: #c20cb9; font-weight: bold;">cat</span> .<span style="color: #000000; font-weight: bold;">/</span>tmp <span style="color: #000000; font-weight: bold;">&gt;</span> .<span style="color: #000000; font-weight: bold;">/</span>databasename-latin1.sql<br />
<span style="color: #c20cb9; font-weight: bold;">rm</span> <span style="color: #660033;">-f</span> .<span style="color: #000000; font-weight: bold;">/</span>tmp</div></td></tr></tbody></table></div>
<p>Now you need to replace all instances of &#8216;CHARSET=latin1&#8242;</p>
<div class="codecolorer-container bash default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br /></div></td><td><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #c20cb9; font-weight: bold;">cat</span> .<span style="color: #000000; font-weight: bold;">/</span>databasename-latin1.sql <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">sed</span> <span style="color: #ff0000;">'s/CHARSET=latin1/CHARSET=utf8/g'</span> <span style="color: #000000; font-weight: bold;">&gt;</span> tmp<br />
<span style="color: #c20cb9; font-weight: bold;">cat</span> .<span style="color: #000000; font-weight: bold;">/</span>tmp <span style="color: #000000; font-weight: bold;">&gt;</span> .<span style="color: #000000; font-weight: bold;">/</span>databasename-latin1.sql<br />
<span style="color: #c20cb9; font-weight: bold;">rm</span> <span style="color: #660033;">-f</span> .<span style="color: #000000; font-weight: bold;">/</span>tmp</div></td></tr></tbody></table></div>
<p>Now we have to run the file through the charset converter</p>
<div class="codecolorer-container bash default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br /></div></td><td><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">sysadmin <span style="color: #660033;">-c</span> iconv <span style="color: #660033;">-d</span> .<span style="color: #000000; font-weight: bold;">/</span>databasename-latin1.sql,latin-<span style="color: #000000;">1</span>,utf-<span style="color: #000000;">8</span></div></td></tr></tbody></table></div>
<p>If your sql dump is over 30mb, you will be prompted to confirm you wish to proceed, please remember that this will load the entire file into memory, so ensure you have enough available system memory before proceeding, I also suggest not running this on a production server.</p>
<p>If any characters could not be converted you will be alerted to their exact position within the file, from there you will either need to use sed to replace the character or use your text editor.</p>
<p>If all went well you now have ./databasename-latin1.sql.utf-8 (note the utf-8 extension), you now have a complete utf8 mySQL dump, all you need do now is import the dump.</p>
<p><strong>
<ul>Further reading</ul>
<p></strong></p>
<ol>
<li><a href="http://www.saiweb.co.uk/mysql/mysql-forcing-utf-8-compliance-for-all-connections">Force mySQL utf8 connections</a></li>
<li><a href="http://www.saiweb.co.uk/mysql/mysql-bash-backup-script">mySQL backup script</a></li>
</ol>
<p><span style="float: left;" ><a class="twitter-share-button"  data-via="Saiweb" data-count="horizontal" data-related="Saiweb:David Busby" data-lang="en" data-url="http://www.saiweb.co.uk/mysql/converting-mysql-latin1-to-utf8" data-text="Converting mySQL latin1 to utf8" href="http://twitter.com/share?via=Saiweb&#038;count=horizontal&#038;related=Saiweb%3ADavid%20Busby&#038;lang=en&#038;url=http%3A%2F%2Fwww.saiweb.co.uk%2Fmysql%2Fconverting-mysql-latin1-to-utf8&#038;text=Converting%20mySQL%20latin1%20to%20utf8" >Tweet</a></span></p>
]]></content:encoded>
			<wfw:commentRss>http://www.saiweb.co.uk/mysql/converting-mysql-latin1-to-utf8/feed</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
	</channel>
</rss>

<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Page Caching using apc
Database Caching 6/14 queries in 0.007 seconds using apc
Object Caching 851/863 objects using apc
Content Delivery Network via Rackspace Cloud Files: cdn.saiweb.co.uk

Served from: www.saiweb.co.uk @ 2012-02-07 16:53:44 -->
