<?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 Noted Path by Theodore Nguyen-Cao &#187; mysql</title>
	<atom:link href="http://www.theodorenguyen-cao.com/tag/mysql/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.theodorenguyen-cao.com</link>
	<description>Personal blog of Theodore Nguyen-Cao</description>
	<lastBuildDate>Fri, 20 May 2011 12:43:52 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=</generator>
		<item>
		<title>Reduce MySQL memory usage</title>
		<link>http://www.theodorenguyen-cao.com/2008/12/07/reduce-mysql-memory-usage/</link>
		<comments>http://www.theodorenguyen-cao.com/2008/12/07/reduce-mysql-memory-usage/#comments</comments>
		<pubDate>Sun, 07 Dec 2008 23:13:35 +0000</pubDate>
		<dc:creator>Theo</dc:creator>
				<category><![CDATA[tutorials]]></category>
		<category><![CDATA[how-to]]></category>
		<category><![CDATA[mysql]]></category>

		<guid isPermaLink="false">http://www.theodorenguyen-cao.com/?p=160</guid>
		<description><![CDATA[As I am running more and more on my 256mb slice, I&#8217;m trying to squeeze more performance out of the system. After a bit of digging, I&#8217;ve made a few changes. First thing I did was switch out the default mysql config with one tweaked for smaller boxes. This configuration actually came with the mysql [...]]]></description>
			<content:encoded><![CDATA[<p>As I am running more and more on my 256mb <a href="https://manage.slicehost.com/customers/new?referrer=ea4080140dbc12aa766f25a2f4ad1c66 ">slice</a>, I&#8217;m trying to squeeze more performance out of the system.  After a bit of digging, I&#8217;ve made a few changes.</p>
<p>First thing I did was switch out the default mysql config with one tweaked for smaller boxes.  This configuration actually came with the mysql installation under <code>/usr/share/doc/mysql-server-5.0/examples/</code>. Just backup your existing my.cnf (mine is located under <code>/etc/mysql</code>) and use the following:</p>
<pre name="code" class="ruby">
# The following options will be passed to all MySQL clients
[client]
port		= 3306
socket		= /var/run/mysqld/mysqld.sock

# Here follows entries for some specific programs

# The MySQL server
[mysqld]
port		= 3306
socket		= /var/run/mysqld/mysqld.sock
skip-locking
key_buffer = 16K
max_allowed_packet = 1M
table_cache = 4
sort_buffer_size = 64K
read_buffer_size = 256K
read_rnd_buffer_size = 256K
net_buffer_length = 2K
thread_stack = 64K

# Don't listen on a TCP/IP port at all. This can be a security enhancement,
# if all processes that need to connect to mysqld run on the same host.
# All interaction with mysqld must be made via Unix sockets or named pipes.
# Note that using this option without enabling named pipes on Windows
# (using the "enable-named-pipe" option) will render mysqld useless!
#
#skip-networking
server-id	= 1

# Uncomment the following if you want to log updates
#log-bin=mysql-bin

# Uncomment the following if you are NOT using BDB tables
#skip-bdb

# Uncomment the following if you are using InnoDB tables
#innodb_data_home_dir = /var/lib/mysql/
#innodb_data_file_path = ibdata1:10M:autoextend
#innodb_log_group_home_dir = /var/lib/mysql/
#innodb_log_arch_dir = /var/lib/mysql/
# You can set .._buffer_pool_size up to 50 - 80 %
# of RAM but beware of setting memory usage too high
#innodb_buffer_pool_size = 16M
#innodb_additional_mem_pool_size = 2M
# Set .._log_file_size to 25 % of buffer pool size
#innodb_log_file_size = 5M
#innodb_log_buffer_size = 8M
#innodb_flush_log_at_trx_commit = 1
#innodb_lock_wait_timeout = 50

[mysqldump]
quick
max_allowed_packet = 16M

[mysql]
no-auto-rehash
# Remove the next comment character if you are not familiar with SQL
#safe-updates

[isamchk]
key_buffer = 8M
sort_buffer_size = 8M

[myisamchk]
key_buffer = 8M
sort_buffer_size = 8M

[mysqlhotcopy]
interactive-timeout
</pre>
<p>You can see estimated memory usage with a config if you just copy paste the configuration file <a href="http://www.omh.cc/mycnf/">here</a>.</p>
<p>Restart MySQL (<code>/etc/init.d/mysql restart</code>).</p>
<p>The second thing I did was check out <a href="http://wiki.mysqltuner.com/MySQLTuner">MySQLTuner</a>.  Just download the perl script and run it.  It will run some analysis on your mysql setup and provide some performance and configuration tweak recommendations.</p>
<p>Sample output looks like this:</p>
<pre name="code" class="console">
 >>  MySQLTuner 1.0.0 - Major Hayden <major@mhtx.net>
 >>  Bug reports, feature requests, and downloads at http://mysqltuner.com/
 >>  Run with '--help' for additional options and output filtering
Please enter your MySQL administrative login: root
Please enter your MySQL administrative password: 

-------- General Statistics --------------------------------------------------
[--] Skipped version check for MySQLTuner script
[OK] Currently running supported MySQL version 5.0.51a-3ubuntu5.4
[OK] Operating on 64-bit architecture

-------- Storage Engine Statistics -------------------------------------------
[--] Status: +Archive -BDB -Federated +InnoDB -ISAM -NDBCluster
[--] Data in MyISAM tables: 867K (Tables: 18)
[--] Data in InnoDB tables: 704K (Tables: 40)
[!!] Total fragmented tables: 2

-------- Performance Metrics -------------------------------------------------
[--] Up for: 14h 57m 0s (17K q [0.316 qps], 699 conn, TX: 55M, RX: 3M)
[--] Reads / Writes: 96% / 4%
[--] Total buffers: 26.0M global + 824.0K per thread (100 max threads)
[OK] Maximum possible memory usage: 106.5M (41% of installed RAM)
[OK] Slow queries: 0% (0/17K)
[OK] Highest usage of available connections: 6% (6/100)
[!!] Key buffer size / total MyISAM indexes: 16.0K/381.0K
[!!] Key buffer hit rate: 88.5% (154K cached / 17K reads)
[!!] Query cache is disabled
[OK] Sorts requiring temporary tables: 0% (0 temp sorts / 4K sorts)
[!!] Temporary tables created on disk: 30% (1K on disk / 4K total)
[!!] Thread cache is disabled
[!!] Table cache hit rate: 0% (4 open / 7K opened)
[OK] Open file limit used: 0% (8/1K)
[OK] Table locks acquired immediately: 99% (17K immediate / 17K locks)
[OK] InnoDB data size / buffer pool: 704.0K/8.0M

-------- Recommendations -----------------------------------------------------
General recommendations:
    Run OPTIMIZE TABLE to defragment tables for better performance
    MySQL started within last 24 hours - recommendations may be inaccurate
    Enable the slow query log to troubleshoot bad queries
    When making adjustments, make tmp_table_size/max_heap_table_size equal
    Reduce your SELECT DISTINCT queries without LIMIT clauses
    Set thread_cache_size to 4 as a starting value
    Increase table_cache gradually to avoid file descriptor limits
Variables to adjust:
    key_buffer_size (> 381.0K)
    query_cache_size (>= 8M)
    tmp_table_size (> 32M)
    max_heap_table_size (> 16M)
    thread_cache_size (start at 4)
    table_cache (> 4)
</pre>
<p>I haven&#8217;t made any of the recommended changes yet though. I am going to try to see how this default small config performs.</p>
<p>I&#8217;ll try to follow up with any of my findings.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.theodorenguyen-cao.com/2008/12/07/reduce-mysql-memory-usage/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

