<?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>A-Connect &#187; slow query log</title>
	<atom:link href="http://a-connect.co.uk/tag/slow-query-log/feed/" rel="self" type="application/rss+xml" />
	<link>http://a-connect.co.uk</link>
	<description>Cornwall Web Design</description>
	<lastBuildDate>Wed, 09 Nov 2011 12:19:33 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>Speeding up MySQL</title>
		<link>http://a-connect.co.uk/mysql/speeding-up-mysql/</link>
		<comments>http://a-connect.co.uk/mysql/speeding-up-mysql/#comments</comments>
		<pubDate>Wed, 01 Jul 2009 11:13:37 +0000</pubDate>
		<dc:creator>a_connect</dc:creator>
				<category><![CDATA[MySQL]]></category>
		<category><![CDATA[config]]></category>
		<category><![CDATA[EXPLAIN]]></category>
		<category><![CDATA[indexes]]></category>
		<category><![CDATA[my.cnf]]></category>
		<category><![CDATA[optimising]]></category>
		<category><![CDATA[slow query log]]></category>

		<guid isPermaLink="false">http://a-connect.co.uk/?p=44</guid>
		<description><![CDATA[I recently rebuilt the Cornwall24 website in the hope that upgrading from a 3 year old verwion of PostNuke to a new version of WordPress might stop the site taking down the server by overloading MySQL at least once a week. Unfortunately it actually made things worse! So I decided to take the bull by [...]]]></description>
			<content:encoded><![CDATA[<p>I recently rebuilt the <a href="http://www.cornwall24.co.uk/" target="_blank">Cornwall24 </a>website in the hope that upgrading from a 3 year old verwion of PostNuke to a new version of WordPress might stop the site taking down the server by overloading MySQL at least once a week.<br />
Unfortunately it actually made things worse!</p>
<p>So I decided to take the bull by the horns and find out what exactly was causing the overload and how I could increase MySQL performance.</p>
<h2>my.cnf</h2>
<p>A good starting point is the MySQL config file on your server. Mine is located at /etc/my.cnf. It seems the default set up and example files are for 1970s server with 32mb of RAM!</p>
<p>For a modern server with 1gb of RAM the my-large.cnf is probably a good starting point (you can find these in /usr/share/doc/mysl-server-[versio]) .<br />
From here there are several tweaks but perhaps the biggest improvement will be by making sure caching is turned on.</p>
<p>Under the [mysqld] config settings add:</p>
<pre>query_cache_type=1</pre>
<pre>query_cache_limit=1M</pre>
<pre>query_cache_size=32M</pre>
<h2>Log Slow Queries</h2>
<p>The best way to find out what is hogging your MySQL resources is to log slow queries. This is done by adding something like the following lines of code to your my.cnf:</p>
<pre>log-slow-queries = slow.log
long_query_time = 2</pre>
<p>This will write any query taking more than 2 seconds to the slow query log. I used a relative path here as absolute ones didn&#8217;t seem to work on my server. The slow log can be found in the MySQL data folder at /var/lib/mysql on my box</p>
<p>NOTE: you&#8217;ll need to restart MySQL for any of the above changes to take effect:</p>
<pre>/etc/init.d/mysqld restart</pre>
<h2>Optimising Slow Queries</h2>
<p>Armed with the information from the slow query log you can set about tweaking the queries that are slowing things up. The slow log gives us several useful bits of info besides the query itself. This includes time taken and number of rows examined &#8211; if this number is particularly high then it probably means your table&#8217;s indexes need looking at (it usually is)</p>
<h2>The EXPLAIN Command</h2>
<p>MySQL&#8217;s EXPLAIN command is perhaps your most useful tool in working out what indexing strategy to use. I&#8217;m only going to touch on this as it is a pretty complicated topic that I barely understand myself!</p>
<p>The useful info that can be gleaned from the EXPLAIN command are whether the indexes you have set up are being used for a particular query. To use the EXPLAIN command just place &#8216;EXPLAIN&#8217; in front of the query you are analysing.</p>
<p>More to come&#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://a-connect.co.uk/mysql/speeding-up-mysql/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
<!-- WP Super Cache is installed but broken. The path to wp-cache-phase1.php in wp-content/advanced-cache.php must be fixed! -->
