<?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>LazyTechie &#187; MySQL</title>
	<atom:link href="http://lazytechie.com/tag/mysql/feed/" rel="self" type="application/rss+xml" />
	<link>http://lazytechie.com</link>
	<description>SomeThing About Technology</description>
	<lastBuildDate>Fri, 26 Mar 2010 06:56:53 +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>Top 84 MySQL Performance Tips</title>
		<link>http://lazytechie.com/top-84-mysql-performance-tips/</link>
		<comments>http://lazytechie.com/top-84-mysql-performance-tips/#comments</comments>
		<pubDate>Wed, 17 Jun 2009 12:01:32 +0000</pubDate>
		<dc:creator>Rajesh</dc:creator>
				<category><![CDATA[Security]]></category>
		<category><![CDATA[Tips & Tricks]]></category>
		<category><![CDATA[MySQL]]></category>

		<guid isPermaLink="false">http://lazytechie.com/?p=251</guid>
		<description><![CDATA[MySQL is a widely used and fast SQL database server. It is a client/server implementation that consists of a server daemon (mysqld) and many different client programs/libraries. Here are very useful tips for all mysql DBA&#8217;s, Developers these tips are noted from MySQL Camp 2006 suggested by mysql community experts. Kaj (Most Excellent Obvious Facilitator) [...]]]></description>
			<content:encoded><![CDATA[<p>MySQL is a widely used and fast SQL database server. It is a client/server implementation that consists of a server daemon (mysqld) and many different client programs/libraries.</p>
<p>Here are very useful tips for all mysql DBA&#8217;s, Developers these tips are noted from MySQL Camp 2006 suggested by mysql community experts.</p>
<ol type="1">
<li>Kaj      (Most Excellent Obvious Facilitator) Index stuff.</li>
<li>Ronald      Don&#8217;t Index Everything</li>
<li>Use      benchmarking</li>
<li>Minimize      traffic by fetching only what you need.
<ol type="1">
<li>Paging/chunked       data retrieval to limit</li>
<li>Don&#8217;t       use SELECT *</li>
<li>Be       wary of lots of small quick queries if a longer query can be more       efficient</li>
</ol>
</li>
<li>Use      EXPLAIN to profile the query execution plan</li>
<li>Use      Slow Query Log (always have it on!)</li>
<li>Don&#8217;t      use DISTINCT when you have or could use GROUP BY</li>
<li>Use      proper data partitions
<ol type="1">
<li>For       Cluster.       Start thinking about Cluster *before* you need them</li>
</ol>
</li>
<li>Insert      performance
<ol type="1">
<li>Batch       INSERT and REPLACE</li>
<li>Use       LOAD DATA instead of INSERT</li>
</ol>
</li>
<li>LIMIT      m,n may not be as fast as it sounds</li>
<li>Don&#8217;t      use ORDER BY RAND() if you have &gt; ~2K records</li>
<li>Use      SQL_NO_CACHE when you are SELECTing frequently updated data or large sets      of data</li>
<li>avoid      wildcards at the start of LIKE queries</li>
<li>avoid      correlated subqueries and in select and where clause (try to avoid in)</li>
<li>config      params -</li>
<li>no      calculated comparisons &#8211; isolate indexed columns</li>
<li>innodb_flush_commit=0      can help slave lag</li>
<li>ORDER      BY and LIMIT work best with equalities and covered indexes</li>
<li>isolate      workloads don&#8217;t let administrative work interfere with customer      performance. (ie backups)</li>
<li>use      optimistic locking, not pessimistic locking. try to use shared lock, not      exclusive lock. share mode vs. FOR UPDATE</li>
<li>use      row-level instead of table-level locking for OLTP workloads</li>
<li>Know      your storage      engines and what performs best for your needs, know that      different ones exist.
<ol type="1">
<li>use       MERGE tables ARCHIVE tables for logs</li>
</ol>
</li>
<li>Optimize      for data types, use consistent data types. Use PROCEDURE ANALYSE() to help      determine if you need less</li>
<li>separate      text/blobs from metadata, don&#8217;t put text/blobs in results if you don&#8217;t      need them</li>
<li>if      you can, compress text/blobs</li>
<li>compress      static data</li>
<li>don&#8217;t      back up static data as often</li>
<li>derived      tables (subqueries in the FROM clause) can be useful for retrieving BLOBs      w/out sorting them. (self-join can speed up a query if 1st part finds the      IDs and use it to fetch the rest)</li>
<li>enable      and increase the query and buffer caches if appropriate</li>
<li>ALTER      TABLE&#8230;ORDER BY can take chronological data and re-order it by a different      field</li>
<li>InnoDB      ALWAYS keeps the primary key as part of each index, so do not make the      primary key very large, be careful of redundant columns in an index, and      this can make the query faster</li>
<li>Do      not duplicate indexes</li>
<li>Utilize      different storage engines on master/slave ie, if you need fulltext      indexing on a table.</li>
<li>BLACKHOLE      engine and replication is much faster than FEDERATED tables for things      like logs.</li>
<li>Design      sane query schemas. don&#8217;t be afraid of table joins, often they are faster      than denormalization</li>
<li>Don&#8217;t      use boolean flags</li>
<li>Use      a clever key and ORDER BY instead of MAX</li>
<li>Keep      the database host as clean as possible. Do you really need a windowing      system on that server?</li>
<li>Utilize      the strengths of the OS</li>
<li>Hire      a MySQL <sup>TM</sup> Certified DBA</li>
<li>Know      that there are many consulting companies out there that can help, as well      as MySQL&#8217;s Professional Services.</li>
<li>Config      variables &amp; tips:
<ol type="1">
<li>use       one of the supplied config files</li>
<li>key_buffer,       unix cache (leave some RAM free), per-connection variables, innodb memory       variables</li>
<li>be       aware of global vs. per-connection variables</li>
<li>check       SHOW STATUS and SHOW VARIABLES (GLOBAL|SESSION in 5.0 and up)</li>
<li>be       aware of swapping esp. with Linux, &#8220;swappiness&#8221; (bypass OS filecache for       innodb data       files, innodb_flush_method=O_DIRECT if possible (this is also       OS specific))</li>
<li>defragment       tables, rebuild indexes, do table maintenance</li>
<li>If       you use innodb_flush_txn_commit=1, use a battery-backed hardware cache       write controller</li>
<li>more       RAM is good so faster disk speed</li>
<li>use       64-bit architectures</li>
</ol>
</li>
<li>Know      when to split a complex query and join smaller ones</li>
<li>Debugging      sucks, testing rocks!</li>
<li>Delete      small amounts at a time if you can</li>
<li>Archive      old data &#8211; don&#8217;t be a pack-rat! 2 common engines for this are ARCHIVE      tables and MERGE tables</li>
<li>use      INET_ATON and INET_NTOA for IP addresses, not char or varchar</li>
<li>make      it a habit to REVERSE() email      addresses, so you can easily search domains</li>
<li>-skip-name-resolve</li>
<li>increase      myisam_sort_buffer_size to optimize large inserts (this is a      per-connection variable)</li>
<li>look      up memory tuning parameter for on-insert caching</li>
<li>increase      temp table size in a data      warehousing environment (default is 32Mb) so it doesn&#8217;t write      to disk (also constrained by max_heap_table_size, default 16Mb)</li>
<li>Normalize      first, and denormalize where appropriate.</li>
<li>Databases      are not spreadsheets, even though Access really really looks like one.      Then again, Access isn&#8217;t a real database</li>
<li>In      5.1 BOOL/BIT NOT NULL type is 1 bit, in previous versions it&#8217;s 1 byte.</li>
<li>A      NULL data type can take more room to store than NOT NULL</li>
<li>Choose      appropriate character sets &amp; collations &#8211; UTF16 will store each      character in 2 bytes, whether it needs it or not, latin1 is faster than      UTF8.</li>
<li>make      similar queries consistent so cache is used</li>
<li>Have      good SQL query standards</li>
<li>Don&#8217;t      use deprecated features</li>
<li>Use      Triggers wisely</li>
<li>Run      in SQL_MODE=STRICT to help identify warnings</li>
<li>Turning      OR on multiple index fields (&lt;5.0) into UNION may speed things up (with      LIMIT), after 5.0 the index_merge should pick stuff up.</li>
<li>/tmp      dir on battery-backed write cache</li>
<li>consider      battery-backed RAM for innodb logfiles</li>
<li>use      min_rows and max_rows to specify approximate data size so space can be      pre-allocated and reference points can be calculated.</li>
<li>as      your data grows, indexing may change (cardinality and selectivity change).      Structuring may want to change. Make your schema as modular as your code.      Make your code able to scale. Plan and embrace change, and get developers      to do the same.</li>
<li>pare      down cron scripts</li>
<li>create      a test environment</li>
<li>try      out a few schemas and storage engines in your test environment before      picking one.</li>
<li>Use      HASH indexing for indexing across columns with similar data prefixes</li>
<li>Use      myisam_pack_keys for int data</li>
<li>Don&#8217;t      use COUNT * on Innodb tables for every search, do it a few times and/or      summary tables, or if you need it for the total # of rows, use      SQL_CALC_FOUND_ROWS and SELECT FOUND_ROWS()</li>
<li>use      -safe-updates for client</li>
<li>Redundant      data is redundant</li>
<li>Use      INSERT &#8230; ON DUPLICATE KEY update (INSERT IGNORE) to avoid having to SELECT</li>
<li>use      groupwise maximum instead of subqueries</li>
<li>be      able to change your schema without ruining functionality of your code</li>
<li>source      control schema and config files</li>
<li>for      LVM innodb backups, restore to a different instance of MySQL so Innodb can      roll forward</li>
<li>use      multi_query if appropriate to reduce round-trips</li>
<li>partition      appropriately</li>
<li>partition      your database when you have real data</li>
<li>segregate      tables/databases that benefit from different configuration variables</li>
</ol>
<p>Source: <a href="http://forge.mysql.com/wiki/Top10SQLPerformanceTips/" target="_blank">MySQL</a></p>



		<!-- Added by WP-DragToShare-eXtended Plugin -->
		<script type="text/javascript">
			dtsv.dtse_post_251_permalink = 'http://lazytechie.com/top-84-mysql-performance-tips/';
			dtsv.dtse_post_251_title = 'Top 84 MySQL Performance Tips';
		</script>
		<!-- End of WP-DragToShare-eXtended Plugin -->]]></content:encoded>
			<wfw:commentRss>http://lazytechie.com/top-84-mysql-performance-tips/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
	</channel>
</rss>
