<?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>Techie Corner &#187; Database Tuning</title>
	<atom:link href="http://www.techiecorner.com/category/database-tuning/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.techiecorner.com</link>
	<description>The place for computer tips and tricks! microsoft windows, open source, database, programming, freeware and etc</description>
	<lastBuildDate>Mon, 06 Sep 2010 01:26:55 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Turn on MySQL query cache to speed up query performance?</title>
		<link>http://www.techiecorner.com/45/turn-on-mysql-query-cache-to-speed-up-mysql-query-performance/</link>
		<comments>http://www.techiecorner.com/45/turn-on-mysql-query-cache-to-speed-up-mysql-query-performance/#comments</comments>
		<pubDate>Tue, 10 Oct 2006 16:03:12 +0000</pubDate>
		<dc:creator>chua</dc:creator>
				<category><![CDATA[Database Tuning]]></category>
		<category><![CDATA[MySQL Database]]></category>
		<category><![CDATA[boost performance]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[mysql db]]></category>
		<category><![CDATA[mysql db server]]></category>
		<category><![CDATA[mysql performance tuning]]></category>
		<category><![CDATA[mysql query cache]]></category>
		<category><![CDATA[mysql server]]></category>
		<category><![CDATA[mysql server tuning]]></category>
		<category><![CDATA[mysql tuning]]></category>
		<category><![CDATA[query cache]]></category>

		<guid isPermaLink="false">http://www.techiecorner.com/45/turn-on-mysql-query-cache-to-speed-up-mysql-query-performance/</guid>
		<description><![CDATA[Many times developers looking for ways to speed up query, in mysql we can enable query cache to speed up query performance. Whenever query cache is enable, it will cache the query in memory and boost query performance. As we know, speed is always the most important element in developing a website especially for those [...]]]></description>
			<content:encoded><![CDATA[<p>Many times developers looking for ways to speed up query, in mysql we can enable query cache to speed up query performance. Whenever query cache is enable, it will cache the query in memory and boost query performance.</p>
<p>As we know, speed is always the most important element in developing a website especially for those high traffic database driven website. You can try to turn on query cache to speed up query. </p>
<p>To speed up query, enable the MySQL query cache, before that you need to set few variables in mysql configuration file (usually is <strong>my.cnf</strong> or <strong>my.ini</strong>)</p>
<p><span id="more-45"></span></p>
<p>- 1st, set <strong>query_cache_type</strong> to 1. (There are 3 possible settings: 0 (disable / off), 1 (enable / on) and 2 (on demand).</p>
<blockquote><p><strong>query-cache-type = 1</strong></p></blockquote>
<p>- 2nd, set query_cache_size to your expected size. I&#8217;d prefer to set it at 20MB. </p>
<blockquote><p><strong>query-cache-size = 20M</strong></p></blockquote>
<p>If you set your query-cache-type = 2 ( on demand ), you would wan to modify your sql query to support cache.</p>
<blockquote><p><strong>SELECT SQL_CACHE field1, field2 FROM table1 WHERE field3 = &#8216;yes&#8217;</strong></p></blockquote>
<p>To check if your mysql server already enable query cache, simply run this query:-</p>
<blockquote><p><strong>SHOW VARIABLES LIKE &#8216;%query_cache%&#8217;;</strong></p></blockquote>
<p>You will see this result:-</p>
<blockquote><p>
+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-+&#8212;&#8212;&#8212;+<br />
| Variable_name     | Value   |<br />
+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-+&#8212;&#8212;&#8212;+<br />
| have_query_cache  | YES     |<br />
| query_cache_limit | 1048576 |<br />
| query_cache_size  | 20971520 |<br />
| query_cache_type  | ON      |<br />
+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-+&#8212;&#8212;&#8212;+<br />
4 rows in set (0.06 sec)
</p></blockquote>
<p>To check if your MySQL query cache is working, simply perform a sql query for 2 times and check the query cache variable like below:-</p>
<blockquote><p><strong>SHOW STATUS LIKE &#8216;%qcache%&#8217;;</strong></p></blockquote>
<blockquote><p>
+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-+&#8212;&#8212;&#8212;-+<br />
| Variable_name           | Value    |<br />
+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-+&#8212;&#8212;&#8212;-+<br />
| Qcache_queries_in_cache | 1        |<br />
| Qcache_inserts          | 3        |<br />
| Qcache_hits             | 0        |<br />
| Qcache_lowmem_prunes    | 0        |<br />
| Qcache_not_cached       | 2        |<br />
| Qcache_free_memory      | 20947592 |<br />
| Qcache_free_blocks      | 1        |<br />
| Qcache_total_blocks     | 4        |<br />
+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-+&#8212;&#8212;&#8212;-+
</p></blockquote>
<p>For the first time you execute your SQL query, the time it should take take be longer compare to the second time query. This is due to the MySQL query cache is working!</p>
<p><a href="http://dev.mysql.com/tech-resources/articles/mysql-query-cache.html">To know more about MySQL query cache click here</a></p>
<p class="simpletags">Technorati Tags: <a href="http://technorati.com/tag/mysql+tuning" rel="tag">mysql tuning</a>, <a href="http://technorati.com/tag/mysql+server+tuning" rel="tag"> mysql server tuning</a>, <a href="http://technorati.com/tag/mysql+performance+tuning" rel="tag"> mysql performance tuning</a>, <a href="http://technorati.com/tag/mysql" rel="tag"> mysql</a>, <a href="http://technorati.com/tag/mysql+server" rel="tag"> mysql server</a>, <a href="http://technorati.com/tag/mysql+db" rel="tag"> mysql db</a>, <a href="http://technorati.com/tag/mysql+db+server" rel="tag"> mysql db server</a>, <a href="http://technorati.com/tag/mysql+query+cache" rel="tag"> mysql query cache</a>, <a href="http://technorati.com/tag/query+cache" rel="tag"> query cache</a>, <a href="http://technorati.com/tag/boost+performance" rel="tag"> boost performance</a></p>
<!-- link start -->
						<script type="text/javascript"><!--
						google_ad_client = "pub-9874157950618711";
						/* Tech HLink After Post */
						google_ad_slot = "4582592668";
						google_ad_width = 468;
						google_ad_height = 15;
						//-->
						</script>
						<script type="text/javascript"
						src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
						</script>
						<!-- link end -->]]></content:encoded>
			<wfw:commentRss>http://www.techiecorner.com/45/turn-on-mysql-query-cache-to-speed-up-mysql-query-performance/feed/</wfw:commentRss>
		<slash:comments>12</slash:comments>
		</item>
	</channel>
</rss>

<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Page Caching using disk (user agent is rejected)
Database Caching 9/18 queries in 0.220 seconds using disk
Object Caching 194/322 objects using disk

Served from: www.techiecorner.com @ 2010-09-07 06:40:49 -->