<?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>Too Far Afield &#187; mysql</title>
	<atom:link href="http://blog.nachtarbeiter.net/tag/mysql/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.nachtarbeiter.net</link>
	<description></description>
	<lastBuildDate>Tue, 16 Feb 2010 07:02:12 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Display MySQL query output on the command line</title>
		<link>http://blog.nachtarbeiter.net/2010/01/19/display-mysql-query-output-on-the-command-line/</link>
		<comments>http://blog.nachtarbeiter.net/2010/01/19/display-mysql-query-output-on-the-command-line/#comments</comments>
		<pubDate>Tue, 19 Jan 2010 05:40:07 +0000</pubDate>
		<dc:creator>Patrick</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[mysql]]></category>

		<guid isPermaLink="false">http://blog.nachtarbeiter.net/?p=887</guid>
		<description><![CDATA[If you are using the MySQL command line client regularly, the following scenario might be familiar to you: You run a select on a table, which contains a lot of fields. The output will not fit on one line, which means that it will be unreadable. Consider the following example: mysql&#62; SELECT * FROM posts [...]]]></description>
			<content:encoded><![CDATA[<p>If you are using the MySQL command line client regularly, the following scenario might be familiar to you: You run a select on a table, which contains a lot of fields. The output will not fit on one line, which means that it will be unreadable. Consider the following example:</p>
<ol class="code">
<li><code>mysql&gt; SELECT * FROM posts LIMIT 1;</code></li>
<li><code>+----+-------------+---------------------+---------------------+--------------------------------+--------------+-----------</code></li>
<li><code>----+--------------+----------+----------+-------------+----------------+-------------+---------------+-------------+----</code></li>
<li><code>-----+--------+---------------------+---------------------+-----------------------+-------------+-------+------------+----</code></li>
<li><code>-------+----------------+---------------+</code></li>
<li><code>| ID | post_author | post_date           | post_date_gmt       | post_content                   | post_title   | </code></li>
<li><code>post_category | post_excerpt | post_lat | post_lon | post_status | comment_status | ping_status | </code></li>
<li><code>post_password | post_name   | to_ping | pinged | post_modified       | post_modified_gmt   | </code></li>
<li><code>post_content_filtered | post_parent | guid  | menu_order | post_type | post_mime_type | </code></li>
<li><code>comment_count |</code></li>
<li><code><br />
</code></li>
<li><code>+----+-------------+---------------------+---------------------+--------------------------------+--------------+-----------</code></li>
<li><code>----+--------------+----------+----------+-------------+----------------+-------------+---------------+-------------+----</code></li>
<li><code>-----+--------+---------------------+---------------------+-----------------------+-------------+-------+------------+----</code></li>
<li><code>-------+----------------+---------------+</code></li>
<li><code><br />
|  1 |           1 | 2004-01-17 18:17:37 | 2004-01-17 16:17:37 | We'll see what time brings ... | Hello world! |             1 </code></li>
<li><code>|              |     NULL |     NULL | publish     | closed         | closed      |               | hello-world </code></li>
<li><code>|         |        | 2004-01-17 18:17:37 | 2004-01-17 16:17:37 |                       |           0 | /?p=1 </code></li>
<li><code>|          0 | post      |                |             0 |</code></li>
<li><code><br />
</code></li>
<li><code>+----+-------------+---------------------+---------------------+--------------------------------+--------------+-----------</code></li>
<li><code>----+--------------+----------+----------+-------------+----------------+-------------+---------------+-------------+----</code></li>
<li><code>-----+--------+---------------------+---------------------+-----------------------+-------------+-------+------------+----</code></li>
<li><code>-------+----------------+---------------+</code></li>
<li><code>1 row in set (0.00 sec)</code></li>
</ol>
<p>There is actually a nice solution for this. By default, the command line client uses horizontal mode to display the results of MySQL queries. If you use <code>\G</code> instead of <code>;</code> or <code>\g</code> at the end of the line, your query result will be displayed in vertical mode, which will look a lot better:</p>
<ol class="code">
<li><code>mysql&gt; SELECT * FROM posts LIMIT 1\G</code></li>
<li><code>*************************** 1. row ***************************</code></li>
<li><code>                   ID: 1</code></li>
<li><code>          post_author: 1</code></li>
<li><code>            post_date: 2004-01-17 18:17:37</code></li>
<li><code>        post_date_gmt: 2004-01-17 16:17:37</code></li>
<li><code>         post_content: We'll see what time brings ...</code></li>
<li><code>           post_title: Hello world!</code></li>
<li><code>        post_category: 1</code></li>
<li><code>         post_excerpt: </code></li>
<li><code>             post_lat: NULL</code></li>
<li><code>             post_lon: NULL</code></li>
<li><code>          post_status: publish</code></li>
<li><code>       comment_status: closed</code></li>
<li><code>          ping_status: closed</code></li>
<li><code>        post_password: </code></li>
<li><code>            post_name: hello-world</code></li>
<li><code>              to_ping: </code></li>
<li><code>               pinged: </code></li>
<li><code>        post_modified: 2004-01-17 18:17:37</code></li>
<li><code>    post_modified_gmt: 2004-01-17 16:17:37</code></li>
<li><code>post_content_filtered: </code></li>
<li><code>          post_parent: 0</code></li>
<li><code>                 guid: /?p=1</code></li>
<li><code>           menu_order: 0</code></li>
<li><code>            post_type: post</code></li>
<li><code>       post_mime_type: </code></li>
<li><code>        comment_count: 0</code></li>
<li><code>1 row in set (0.00 sec)</code></li>
</ol>
<p>While vertical output uses a lot more vertical space than the horizontal output, the vertical output is a lot more readable. Now you can probably see what I used as example query. It is actually the first post from this blog. Yes, this blog just got 6 years old <code>;)</code>.</p>
<p>If you want your command line client to use vertical mode by default, you can add <code>vertical</code> to the client section (<code>[client]</code>) of your <code>.my.cnf</code> file. This would look something like this:</p>
<ol class="code">
<li><code>[client]</code></li>
<li><code>vertical</code></li>
</ol>
]]></content:encoded>
			<wfw:commentRss>http://blog.nachtarbeiter.net/2010/01/19/display-mysql-query-output-on-the-command-line/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Storing binary data inside a MySQL database</title>
		<link>http://blog.nachtarbeiter.net/2009/04/28/storing-binary-data-inside-a-mysql-database/</link>
		<comments>http://blog.nachtarbeiter.net/2009/04/28/storing-binary-data-inside-a-mysql-database/#comments</comments>
		<pubDate>Tue, 28 Apr 2009 05:52:33 +0000</pubDate>
		<dc:creator>Patrick</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[base64]]></category>
		<category><![CDATA[binary]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://blog.nachtarbeiter.net/?p=743</guid>
		<description><![CDATA[Sometimes you need to store binary data inside a MySQL database. While there are various field types for binary data in MySQL, its handling of binary data has a share of different problems. As far as I know you might hit some bugs, if you&#8217;re using non-standard connection encodings or character sets. Also, binary data [...]]]></description>
			<content:encoded><![CDATA[<p>Sometimes you need to store binary data inside a <cite>MySQL</cite> database. While there are various field types for binary data in <cite>MySQL</cite>, its handling of binary data has a share of different problems. As far as I know you might hit some bugs, if you&#8217;re using non-standard connection encodings or character sets. Also, binary data is a hell to escape properly. For example, if you store <code>S????'x7?ma?X?UHMh?</code> inside the <cite>MySQL</cite> database you might end up with <code>?????r??v ???????v</code> later under certain conditions. This is not really ideal, to say the least.</p>
<p>The best thing to do is to convert the binary data to a string-based representation, e.g. a hexadecimal form or use a two-way encryption method like <a href="http://en.wikipedia.org/wiki/Base64"><cite>Base64</cite></a>. In fact, I recommend to use <cite>Base64</cite>. The drawback is, that a <cite>Base64</cite> representation uses around 35% more space than the original binary representation. For example, in <cite><abbr title="PHP Hypertext Preprocessor">PHP</abbr></cite> you would do something like this:</p>
<ol class="code">
<li><code>// Encode binary data</code></li>
<li><code>$binary = base64_encode($binary);</code></li>
<li><code>&nbsp;</code></li>
<li><code>// Decode binary data</code></li>
<li><code>$binary = base64_decode($binary);</code></li>
</ol>
<p><em>Update:</em> Changed the example data slightly to accommodate some screen readers, that require a valid feed. Thank you <cite lang="de">Jan</cite> for pointing this out.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.nachtarbeiter.net/2009/04/28/storing-binary-data-inside-a-mysql-database/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
