<?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>OXT blog &#187; mysql</title>
	<atom:link href="http://blog.o-x-t.com/tag/mysql/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.o-x-t.com</link>
	<description>"People say nothing is impossible, but I do nothing every day." - Whinnie The Pooh</description>
	<lastBuildDate>Wed, 25 Aug 2010 19:18:08 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Change charset for all tables.</title>
		<link>http://blog.o-x-t.com/2007/09/24/change-charset-for-all-tables/</link>
		<comments>http://blog.o-x-t.com/2007/09/24/change-charset-for-all-tables/#comments</comments>
		<pubDate>Mon, 24 Sep 2007 13:31:04 +0000</pubDate>
		<dc:creator>alex</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[mysql]]></category>

		<guid isPermaLink="false">http://blog.o-x-t.com/2007/09/24/change-charset-for-all-tables/</guid>
		<description><![CDATA[A lot of linux distributions comes with mysql with default charset latin1. In modern world it seems to be rudimentary, for i18n utf8 is a must. So converting existing mysql databases/tables to utf8 is not an uncommon task. There&#8217;s no problem with it, mysql has ALTER TABLE SET CHARSET statement. But what if you have [...]]]></description>
			<content:encoded><![CDATA[<p>A lot of linux distributions comes with mysql with default charset latin1. In modern world it seems to be rudimentary, for i18n utf8 is a must. So converting existing mysql databases/tables to utf8 is not an uncommon task. There&#8217;s no problem with it, mysql has <code>ALTER TABLE SET CHARSET</code> statement. But what if you have several dozens of tables? And what if each table has a lot of text fields? You&#8217;ll spend a lot of time in front of mysql console or phpmyadmin. Or you&#8217;ll have to generate script from table/field names.<br />
I offer simple solution when all your data is english (I can&#8217;t predict behaviour if you have other data).</p>
<ol>
<li>Make mysqldump of your entire database</li>
<li>Change all charset definitions <code>sed -i 's/latin1/utf8/' dumpfile.sql</code></li>
<li>Load dump back to database</li>
</ol>
]]></content:encoded>
			<wfw:commentRss>http://blog.o-x-t.com/2007/09/24/change-charset-for-all-tables/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Parsing large mysql dumps</title>
		<link>http://blog.o-x-t.com/2007/07/07/parsing-large-mysql-dumps/</link>
		<comments>http://blog.o-x-t.com/2007/07/07/parsing-large-mysql-dumps/#comments</comments>
		<pubDate>Sat, 07 Jul 2007 21:22:50 +0000</pubDate>
		<dc:creator>alex</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[perl]]></category>

		<guid isPermaLink="false">http://blog.o-x-t.com/2007/07/07/parsing-large-mysql-dumps/</guid>
		<description><![CDATA[Recently I faced a problem &#8211; I had large mysql dump on remote machine and I needed just some tables from it. Dump file was about 900 Mb, bzip&#8217;ed &#8211; around 60 Mb. I didn&#8217;t want to download it just for about 1 Mb of required data. First idea that came into my head &#8211; [...]]]></description>
			<content:encoded><![CDATA[<p>Recently I faced a problem &#8211; I had large mysql dump on remote machine and I needed just some tables from it. Dump file was about 900 Mb, bzip&#8217;ed &#8211; around 60 Mb. I didn&#8217;t want to download it just for about 1 Mb of required data. First idea that came into my head &#8211; load this dump to the database on remote machine and then dump again only required tables. The problem that I had no possibility to do that &#8211; I had just ftp/ssh access. So, I opened this ~1Gb sql file with vi. It opened it even with syntax highlighting! But when I tried to remove 2 millions of unnecessary lines it hanged forever&#8230; Emacs wasn&#8217;t better.<br />
<span id="more-3"></span></p>
<p>I had no wish to learn something like sed, so I wrote small perl script for this task. Usage is simple:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">perl</span> strip-dump.pl your-dump-file.sql table1 table2 table3</pre></div></div>

<p>Script source:</p>

<div class="wp_syntax"><div class="code"><pre class="perl" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#!/usr/bin/perl -w</span>
<span style="color: #666666; font-style: italic;">#Get only required tables from the whole dump</span>
<span style="color: #000000; font-weight: bold;">use</span> strict<span style="color: #339933;">;</span>
&nbsp;
<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$dump_file</span> <span style="color: #339933;">=</span> <span style="color: #000066;">shift</span> <span style="color: #0000ff;">@ARGV</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$out_dump_file</span> <span style="color: #339933;">=</span> <span style="color: #ff0000;">'stripped_dump.sql'</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000066;">open</span> DUMP<span style="color: #339933;">,</span> <span style="color: #ff0000;">&quot;&lt;$dump_file&quot;</span> <span style="color: #b1b100;">or</span> <span style="color: #000066;">die</span> <span style="color: #0000ff;">$!</span><span style="color: #339933;">;</span>
<span style="color: #000066;">open</span> OUT<span style="color: #339933;">,</span> <span style="color: #ff0000;">&quot;&gt;$out_dump_file&quot;</span> <span style="color: #b1b100;">or</span> <span style="color: #000066;">die</span> <span style="color: #0000ff;">$!</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">@required_tables</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">@ARGV</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$table_dump_started</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">while</span> <span style="color: #009900;">&#40;</span><span style="color: #009999;">&lt;DUMP&gt;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000066;">index</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$_</span><span style="color: #339933;">,</span> <span style="color: #ff0000;">'CREATE TABLE'</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&gt;=</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #0000ff;">$table_dump_started</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">foreach</span> <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$table</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">@required_tables</span><span style="color: #009900;">&#41;</span>
		<span style="color: #009900;">&#123;</span>
			<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000066;">index</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$_</span><span style="color: #339933;">,</span> <span style="color: #ff0000;">&quot;`$table`&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&gt;=</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span>
			<span style="color: #009900;">&#123;</span>
				<span style="color: #0000ff;">$table_dump_started</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span>
				<span style="color: #b1b100;">last</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span>
		<span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #000066;">print</span> OUT
		<span style="color: #b1b100;">if</span> <span style="color: #0000ff;">$table_dump_started</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000066;">close</span> OUT<span style="color: #339933;">;</span>
<span style="color: #000066;">close</span> DUMP<span style="color: #339933;">;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://blog.o-x-t.com/2007/07/07/parsing-large-mysql-dumps/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
