<?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; MySQL</title>
	<atom:link href="http://www.zulutown.com/blog/tag/mysql/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>Wed, 24 Aug 2011 10:06:02 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Importing an Excel spreadsheet in MySQL to quickly manipulate its data</title>
		<link>http://www.zulutown.com/blog/2011/05/08/importing-an-excel-spreadsheet-in-mysql-to-quickly-manipulate-its-data/</link>
		<comments>http://www.zulutown.com/blog/2011/05/08/importing-an-excel-spreadsheet-in-mysql-to-quickly-manipulate-its-data/#comments</comments>
		<pubDate>Sun, 08 May 2011 12:50:27 +0000</pubDate>
		<dc:creator>Zulutown Webmaster</dc:creator>
				<category><![CDATA[MySQL]]></category>
		<category><![CDATA[csv]]></category>
		<category><![CDATA[excel]]></category>
		<category><![CDATA[libre+office]]></category>
		<category><![CDATA[load+data+local+infile]]></category>
		<category><![CDATA[migrate+data]]></category>
		<category><![CDATA[phonebook]]></category>
		<category><![CDATA[save+as]]></category>
		<category><![CDATA[sql]]></category>
		<category><![CDATA[xls]]></category>

		<guid isPermaLink="false">http://www.zulutown.com/blog/?p=134</guid>
		<description><![CDATA[Microsoft Excel doesn't offer a simple way to achieve some results that are very simple to obtain using SQL in MySQL, in this example it's explained how to migrate some data from Excel to MySQL]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been asked to compute some data and statistics from an Excel spreadsheet containing an huge phonebook</p>
<p>The operations I need wasn&#8217;t very complicated, like to find and remove duplicate rows and so on, but I didn&#8217;t find any quick way to achieve those simple tasks using just Excel (or OpenOffice and LibreOffice).</p>
<p>Since I&#8217;m good in SQL, I decided to move this data in a MySQL database, then I wondered what&#8217;s the simplest way to obtain this result.</p>
<h2>Excel Data Structure</h2>
<p>My excel data is on three simple columns:</p>
<ul>
<li>First Name</li>
<li>Last Name</li>
<li>Phone Number</li>
</ul>
<p>I need to export my 20,000 rows in a .csv file.</p>
<h2>Export XLS Data in a CSV</h2>
<h3>Using Microsoft Excel</h3>
<p>From Excel, go in &#8220;Save As&#8221; then pick the option &#8220;Other Formats&#8221;, and from the combo box, choose Comma Delimited  CSV.</p>
<p>Microsoft Excel  by default creates values separated by a Comma, and the single column is not enclosed by any special char.</p>
<h3>Using OpenOffice or LibreOffice</h3>
<p>In OpenOffice, choose Save As and then CSV, using the default options the .csv file will have values separated by semicolon and enclosed by double quotes.</p>
<h2>Create the MySQL table to import the CSV</h2>
<p>It&#8217;s time to create the basic data structure in MySQL that will be able to host the data we exported from Excel. So the simple task is to generate a table with the same number of columns (and type) that will be associated to the Excel columns.</p>
<pre>create table phonebook (first_name varchar(100), last_name varchar(100), phone_number varchar(100))</pre>
<p>And now, the last step, importing the CSV in MySQL</p>
<h2>Import the CSV (generated from an XLS) into MySQL table</h2>
<p>Mysql offers a useful command for the operation of importing the CSV in a table, the command is LOAD DATA LOCAL INFILE.</p>
<p>And now the code in the case you exported the CSV from OpenOffice and the rows have the following structure:</p>
<p>&#8220;Mario&#8221;,&#8221;Rossi&#8221;,&#8221;+390123456789&#8243;</p>
<p>The code to load the data is:</p>
<p><span style="font-family: Consolas, Monaco, 'Courier New', Courier, monospace; font-size: 12px; line-height: 18px; white-space: pre;">load data local infile &#8216;phonebook.csv&#8217; into table phonebook fields terminated by &#8216;,&#8217; enclosed by &#8216;&#8221;&#8216; lines terminated by &#8216;\n&#8217; (first_name, last_name, phone_number);</span></p>
<p>If you exported using Microsoft Office the rows have the following structure:</p>
<p>Mario;Rossi;+390123456789</p>
<p>The code to load the data is:</p>
<pre>load data local infile 'phonebook.csv' into table phonebook fields terminated by ';' enclosed by '' lines terminated by '\n' (first_name, last_name, phone_number);</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.zulutown.com/blog/2011/05/08/importing-an-excel-spreadsheet-in-mysql-to-quickly-manipulate-its-data/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>SSH Tunnelling to Remote Servers, and with Local Address Binding</title>
		<link>http://www.zulutown.com/blog/2009/02/28/ssh-tunnelling-to-remote-servers-and-with-local-address-binding/</link>
		<comments>http://www.zulutown.com/blog/2009/02/28/ssh-tunnelling-to-remote-servers-and-with-local-address-binding/#comments</comments>
		<pubDate>Sat, 28 Feb 2009 18:10:52 +0000</pubDate>
		<dc:creator>Zulutown Webmaster</dc:creator>
				<category><![CDATA[Networking]]></category>
		<category><![CDATA[System Administration]]></category>
		<category><![CDATA[binding]]></category>
		<category><![CDATA[irc]]></category>
		<category><![CDATA[local]]></category>
		<category><![CDATA[mirc]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[port]]></category>
		<category><![CDATA[remote]]></category>
		<category><![CDATA[ssh]]></category>
		<category><![CDATA[tcp]]></category>
		<category><![CDATA[tunnel]]></category>
		<category><![CDATA[tunnelling]]></category>

		<guid isPermaLink="false">http://www.zulutown.com/blog/?p=85</guid>
		<description><![CDATA[It&#8217;s often required to open different kind of connections to a server where there is available just a SSH account (or where only the port 22 is open). Using ssh tunneling it&#8217;s easy to to access any port on the server, or even to connect to any other servers reachable from the server where the [...]]]></description>
			<content:encoded><![CDATA[<p>It&#8217;s often required to open different kind of connections to a server where there is available just a SSH account (or where only the port <code>22</code> is open).<br />
Using <em>ssh tunneling</em> it&#8217;s easy to to access any port on the server, or even to connect to any other servers reachable from the server where the SSH account is available.</p>
<p>To access directly (i.e. with MySQL Query Browser) a MySQL service on the remote server, where the access to the port <code>3306</code> is denied, the trick is to open a SSH tunnel to the remote server, mapping an arbitrary local port the the remote port <code>3306</code>. In the following example the local port <code>5306</code> is used:</p>
<pre>ssh -L 5306:remoteserver.com:3306 remoteuser@remoteserver.com</pre>
<p>In this case, the local port <code>5306</code> is forwarded (with ssh tunnelling) to <code>remoteserver.com</code>, that attaches the tunnel on its port <code>3306</code>.<br />
When the tunnel is open, it&#8217;s only required to setup MySQL Query Browser to connect on <code>localhost:5306</code> and the connection will be magically forwarded to the remote server on its port <code>3306</code>.</p>
<div id="attachment_86" class="wp-caption alignnone" style="width: 490px"><img class="size-large wp-image-86" title="Simple ssh tunnelling of a MySQL Connection" src="http://www.zulutown.com/blog/wp-content/uploads/2009/02/simple_ssh_tunnelling-480x223.png" alt="Simple ssh tunnelling of a MySQL Connection" width="480" height="223" /><p class="wp-caption-text">Simple ssh tunnelling of a MySQL Connection</p></div>
<p>It&#8217;s even possible to set the remote side of the tunnel to be mapped not on the remote server itself, but on a <em>different host</em>.<br />
For example, if the local computer is not allowed to access IRC servers, an idea could be to use a remote server where a SSH account is available to tunnel the IRC connections.</p>
<p>Here is an example:</p>
<pre>ssh -L 8666:ircserver.org:6666 remoteuser@remoteserver.com</pre>
<p>In this case the local port <code>8666</code> is mapped on the port <code>6666</code> of the IRC server <code>ircserver.org</code>, so the local IRC client (i.e. mIRC) should be simply setup to connect on <code>localhost</code> on the port <code>8666</code>.</p>
<div id="attachment_87" class="wp-caption alignnone" style="width: 490px"><img class="size-large wp-image-87" title="SSH Tunnelling to a Different Remote Host" src="http://www.zulutown.com/blog/wp-content/uploads/2009/02/ssh_tunnelling_to_a_different_remote_host-480x142.png" alt="SSH Tunnelling to a Different Remote Host" width="480" height="142" /><p class="wp-caption-text">SSH Tunnelling to a Different Remote Host</p></div>
<p>Finally, other people in the local network might desire to use the tunnel to the remote server (in this example it&#8217;s a IRC server). If the client that opened the SSH tunnel has the IP address <code>192.168.1.1</code>, the other clients on the local network should connect to <code>192.168.1.1:8666</code> to reach the remote ircserver.org on the port 6666.</p>
<p>In this last case, it&#8217;s important to make sure that the tunnel binds to the correct local IP address.<br />
If the local client has 2 addresses: <code>127.0.0.1</code> and <code>192.168.1.1</code>, it&#8217;s useful to open the tunnel binding it on <code>192.168.1.1</code>. In this way other clients on the LAN can use the tunnel. This is the syntax:</p>
<pre>ssh -L 192.168.1.1:8666:ircserver.org:6666 remoteuser@remoteserver.com</pre>
<div id="attachment_88" class="wp-caption alignnone" style="width: 490px"><img class="size-large wp-image-88" title="SSH Tunnelling with Local Address Binding" src="http://www.zulutown.com/blog/wp-content/uploads/2009/02/ssh_tunnelling_with_address_binding-480x126.png" alt="SSH Tunnelling with Local Address Binding" width="480" height="126" /><p class="wp-caption-text">SSH Tunnelling with Local Address Binding</p></div>
]]></content:encoded>
			<wfw:commentRss>http://www.zulutown.com/blog/2009/02/28/ssh-tunnelling-to-remote-servers-and-with-local-address-binding/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<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 [...]]]></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>6</slash:comments>
		</item>
	</channel>
</rss>

