<?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>Paul Turner &#187; MySQL</title>
	<atom:link href="http://paulturner.me/category/mysql/feed/" rel="self" type="application/rss+xml" />
	<link>http://paulturner.me</link>
	<description>bits and pieces</description>
	<lastBuildDate>Mon, 10 Oct 2011 16: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>MySQL compare NULL equivalent to an empty string</title>
		<link>http://paulturner.me/2010/09/mysql-compare-null-equivalent-to-an-empty-string/</link>
		<comments>http://paulturner.me/2010/09/mysql-compare-null-equivalent-to-an-empty-string/#comments</comments>
		<pubDate>Mon, 27 Sep 2010 13:08:10 +0000</pubDate>
		<dc:creator>Paul</dc:creator>
				<category><![CDATA[MySQL]]></category>
		<category><![CDATA[NULL]]></category>

		<guid isPermaLink="false">http://paulturner.me/?p=176</guid>
		<description><![CDATA[Nearly all MySQL&#8217;s string functions return NULL when a NULL value is used for comparison. Although this is correct sometimes it is useful to compare NULL as being equalivalent to an empty string (although they are technically different). One exception in MySQL&#8217;s string functions is the CONACT_WS function as this skips NULL parameters after the [...]]]></description>
			<content:encoded><![CDATA[<p>Nearly all MySQL&#8217;s string functions return NULL when a NULL value is used for comparison.  Although this is correct sometimes it is useful to compare NULL as being equalivalent to an empty string (although they are technically different).</p>
<p>One exception in MySQL&#8217;s string functions is the <a href="http://dev.mysql.com/doc/refman/5.0/en/string-functions.html#function_concat-ws">CONACT_WS </a> function as this skips NULL parameters after the separator argument.</p>
<p>This means it can be used like this to compare NULL as being equal to an empty string:</p>
<div class="codecolorer-container sql default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="sql codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">CONCAT_WS<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">''</span><span style="color: #66cc66;">,</span>value1<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">=</span> CONCAT_WS<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">''</span><span style="color: #66cc66;">,</span>value2<span style="color: #66cc66;">&#41;</span></div></div>
<p>This will return true if value1 and value2 are any combination of NULL and empty string.</p>
]]></content:encoded>
			<wfw:commentRss>http://paulturner.me/2010/09/mysql-compare-null-equivalent-to-an-empty-string/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>MySQL slow query log</title>
		<link>http://paulturner.me/2008/10/mysql-slow-query-log/</link>
		<comments>http://paulturner.me/2008/10/mysql-slow-query-log/#comments</comments>
		<pubDate>Mon, 13 Oct 2008 16:34:34 +0000</pubDate>
		<dc:creator>Paul</dc:creator>
				<category><![CDATA[MySQL]]></category>

		<guid isPermaLink="false">http://paul-turner.net/?p=63</guid>
		<description><![CDATA[The MySQL slow query log enables you to log all queries that take longer than a specified number of seconds to execute.  This should help identify any queries that are not performing sufficiently. All that is required is two additional lines in the MySQL configuration file &#8220;my.cnf&#8221; in the [mysqld] section. [mysqld] log-slow-queries = /var/log/mysql-slow.log [...]]]></description>
			<content:encoded><![CDATA[<p>The MySQL slow query log enables you to log all queries that take longer than a specified number of seconds to execute.  This should help identify any queries that are not performing sufficiently.</p>
<p>All that is required is two additional lines in the MySQL configuration file &#8220;my.cnf&#8221; in the [mysqld] section.</p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">[mysqld]<br />
log-slow-queries = /var/log/mysql-slow.log<br />
long_query_time = 4</div></div>
<p>The above configuration will log any queries taking longer than 4 seconds to execute in to the specified log file.</p>
<p>MySQL appears to require that the specified log file exists otherwise the logging is disabled and the error below appears in the MySQL log. (Or it may be that it didn&#8217;t have permissions to create the file.  I haven&#8217;t investigated).</p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">081013 14:55:37 [ERROR] Could not use /var/log/mysql-slow.log for logging (error 13). Turning logging off for the whole duration of the MySQL server process. To turn it on again: fix the cause, shutdown the MySQL server and restart it.</div></div>
<p>To create the log file I did the following:</p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">touch /var/log/mysql-slow.log<br />
chown mysql.mysql /var/log/mysql-slow.log<br />
chmod o-r /var/log/mysql-slow.log</div></div>
<p>The third command is probably unnecessary, but it meant that the permissions matched the mysqld.log in the same directory.</p>
<p>Once this is done MySQL needs to be restarted to start the query logging:</p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">service mysql restart</div></div>
]]></content:encoded>
			<wfw:commentRss>http://paulturner.me/2008/10/mysql-slow-query-log/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>MySQL export to CSV</title>
		<link>http://paulturner.me/2008/06/mysql-export-to-csv/</link>
		<comments>http://paulturner.me/2008/06/mysql-export-to-csv/#comments</comments>
		<pubDate>Mon, 02 Jun 2008 15:12:55 +0000</pubDate>
		<dc:creator>Paul</dc:creator>
				<category><![CDATA[MySQL]]></category>

		<guid isPermaLink="false">http://paul-turner.net/blog/?p=3</guid>
		<description><![CDATA[Saving the results of a MySQL query in a format that Excel can use]]></description>
			<content:encoded><![CDATA[<p>MySQL allows you to export a query directly in to a CSV file that can be opened by Microsoft Excel.</p>
<p>This is the basic syntax:</p>
<div class="codecolorer-container sql default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="sql codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #993333; font-weight: bold;">SELECT</span> <span style="color: #993333; font-weight: bold;">FIELDS</span> <span style="color: #993333; font-weight: bold;">FROM</span> <span style="color: #993333; font-weight: bold;">TABLE</span> <span style="color: #993333; font-weight: bold;">INTO</span> <span style="color: #993333; font-weight: bold;">OUTFILE</span> <span style="color: #ff0000;">'/path/to/file_name.csv'</span> <span style="color: #993333; font-weight: bold;">FIELDS</span> <span style="color: #993333; font-weight: bold;">TERMINATED</span> <span style="color: #993333; font-weight: bold;">BY</span> <span style="color: #ff0000;">','</span> <span style="color: #993333; font-weight: bold;">OPTIONALLY</span> <span style="color: #993333; font-weight: bold;">ENCLOSED</span> <span style="color: #993333; font-weight: bold;">BY</span> <span style="color: #ff0000;">'&quot;'</span> <span style="color: #993333; font-weight: bold;">LINES</span> <span style="color: #993333; font-weight: bold;">TERMINATED</span> <span style="color: #993333; font-weight: bold;">BY</span> <span style="color: #ff0000;">'<span style="color: #000099; font-weight: bold;">\n</span>'</span>;</div></div>
<p>The export file that is created &#8220;file_name.csv&#8221; must not already exist, the MySQL user must have write permissions to the directory the file will be created in, and the FILE permission within MySQL.</p>
<p>See the MySQL manual: <a href="http://dev.mysql.com/doc/refman/5.0/en/select.html">SELECT Syntax</a></p>
]]></content:encoded>
			<wfw:commentRss>http://paulturner.me/2008/06/mysql-export-to-csv/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Creating a MySQL unicode UTF-8 database</title>
		<link>http://paulturner.me/2008/05/creating-a-mysql-unicode-utf-8-database/</link>
		<comments>http://paulturner.me/2008/05/creating-a-mysql-unicode-utf-8-database/#comments</comments>
		<pubDate>Sat, 03 May 2008 11:44:14 +0000</pubDate>
		<dc:creator>Paul</dc:creator>
				<category><![CDATA[MySQL]]></category>

		<guid isPermaLink="false">http://paul-turner.net/blog/?p=5</guid>
		<description><![CDATA[Here&#8217;s the syntax for creating a UTF-8 database in MySQL as I can never remember it! CREATE DATABASE `databasename` /*!40100 DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci */;]]></description>
			<content:encoded><![CDATA[<p>Here&#8217;s the syntax for creating a UTF-8 database in MySQL as I can never remember it!</p>
<div class="codecolorer-container sql default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="sql codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #993333; font-weight: bold;">CREATE</span> <span style="color: #993333; font-weight: bold;">DATABASE</span> <span style="color: #ff0000;">`databasename`</span> <span style="color: #808080; font-style: italic;">/*!40100 DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci */</span>;</div></div>
]]></content:encoded>
			<wfw:commentRss>http://paulturner.me/2008/05/creating-a-mysql-unicode-utf-8-database/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

