<?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; MySQL</title>
	<atom:link href="http://a-connect.co.uk/tag/mysql/feed/" rel="self" type="application/rss+xml" />
	<link>http://a-connect.co.uk</link>
	<description>Cornwall Web Design</description>
	<lastBuildDate>Thu, 14 Jan 2010 11:11:37 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Converting MySQL tables to UTF-8</title>
		<link>http://a-connect.co.uk/mysql/converting-mysql-tables-to-utf-8/</link>
		<comments>http://a-connect.co.uk/mysql/converting-mysql-tables-to-utf-8/#comments</comments>
		<pubDate>Thu, 14 Jan 2010 11:11:37 +0000</pubDate>
		<dc:creator>a_connect</dc:creator>
				<category><![CDATA[MySQL]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[character set]]></category>
		<category><![CDATA[UTF]]></category>
		<category><![CDATA[UTF-8]]></category>

		<guid isPermaLink="false">http://a-connect.co.uk/?p=48</guid>
		<description><![CDATA[Quick and easy code to convert the character set of a MySQL table to UTF-8. Of course this works for all character sets not just UTF
ALTER TABLE tbl_name CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci;

]]></description>
			<content:encoded><![CDATA[<p>Quick and easy code to convert the character set of a MySQL table to UTF-8. Of course this works for all character sets not just UTF</p>
<pre>ALTER TABLE tbl_name CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci;
</pre>
]]></content:encoded>
			<wfw:commentRss>http://a-connect.co.uk/mysql/converting-mysql-tables-to-utf-8/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<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 the horns [...]]]></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>
		<item>
		<title>Caching remote MySQL queries with PHP</title>
		<link>http://a-connect.co.uk/php/caching-remote-mysql-queries-with-php/</link>
		<comments>http://a-connect.co.uk/php/caching-remote-mysql-queries-with-php/#comments</comments>
		<pubDate>Sat, 20 Jun 2009 16:06:37 +0000</pubDate>
		<dc:creator>a_connect</dc:creator>
				<category><![CDATA[MySQL]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[cache]]></category>
		<category><![CDATA[caching]]></category>
		<category><![CDATA[caching mysql]]></category>
		<category><![CDATA[class_db]]></category>
		<category><![CDATA[remote mysql]]></category>

		<guid isPermaLink="false">http://a-connect.co.uk/?p=30</guid>
		<description><![CDATA[The problem:
What I wanted to do here was find a way of speeding up a query that was run on MySQL database on a different server. Also I&#8217;m a big fan of caching generally, especially when the data is only updated once or twice a day.
When I was running the queries directly off the remote [...]]]></description>
			<content:encoded><![CDATA[<p><strong>The problem:</strong></p>
<p>What I wanted to do here was find a way of speeding up a query that was run on MySQL database on a different server. Also I&#8217;m a big fan of caching generally, especially when the data is only updated once or twice a day.</p>
<p>When I was running the queries directly off the remote server it was noticably slow but with this solution in place things are flying!</p>
<p>Whilst there are ways of caching MySQL queries using MySQL this would be pretty pointless for a remote query, the only solution was to cache the results locally.</p>
<p><strong>The solution:</strong></p>
<p><a href="http://www.troywolf.com/articles/php/class_db/" target="_blank">class_db.php</a> by Troy Wolf</p>
<p>What this class does is provide an layer between your query and database server (it supports several DBs) which runs the query and then writes the results to a file in a serialized format. E.g.</p>
<blockquote><p>a:10:{i:0;a:8:{s:13:&#8221;Dunster House&#8221;;s:10:&#8221;short_desc&#8221;;s:157:&#8221;A warm welcome to Dunster House. We are a friendly family run Guest House situated within walking distance of Torquay&#8217;s main attractions. Beds from &amp;pound;20&#8243;;s:4:&#8221;town&#8221;;s:7:&#8221;Torquay&#8221;;s:3:&#8221;lat&#8221;;N;s:3:&#8221;lon&#8221;;N;}&#8230;.</p></blockquote>
<p>In the class you need to hard code the details of your DB connection(s) and set up your cache directory. Then it&#8217;s as straightforward as:</p>
<pre>include("class_db.php");

$d = new db(0); //use first connection info from class_db

$sql = "SELECT `id`
 FROM accommodation
 WHERE `type` = ".$catNo;
$q_name = 'num_'.md5($catNo;);
$rows = $d-&gt;fetch($sql, 3600, $q_name);//run query, cache for 1hr, save cahce file as $q_name

foreach($rows as $row){
...
}</pre>
<p>Easy as that. You have now run the query on the remote server and created a cached local result which will be called until it expires.</p>
<p>For an example of the script in action: <a href="http://www.devon-stay.com/Ilfracombe/camping.htm" target="_blank">http://www.devon-stay.com/Ilfracombe/camping.htm</a></p>
<div id="_mcePaste" style="overflow: hidden; position: absolute; left: -10000px; top: 27px; width: 1px; height: 1px;">http://www.devon-stay.com/Ilfracombe/camping.htm</div>
]]></content:encoded>
			<wfw:commentRss>http://a-connect.co.uk/php/caching-remote-mysql-queries-with-php/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

<!-- Dynamic page generated in 0.269 seconds. -->
<!-- Cached page generated by WP-Super-Cache on 2010-05-14 09:15:34 -->
<!-- Compression = gzip -->