I have a Windows 2008 server with 8GB of RAM running IIS7 and MySQL. I've been tracking the memory, cpu and disk usage on the server and I found out that MySQL is using only 250MB of RAM, keeping the disks very busy, even though I have plenty of free ram laying around.
In SQL Server I can easily set the amount of memory I want it to use, I am looking for the same setting in MySQL.
How can I configure MySQL to use more memory and reduce the cpu and disk usage?
Best Answer
table_cache
is the most useful configuration directive to change. Each time MySQL accesses a table, it loads the table into cache. If you've got a high number of tables, it's faster to have them cached.Take a look at your server variables by running:
and have a look for the variable
open_tables
. If this is the same as yourtable_cache
value, andopened_tables
keeps going up, then you need to increase thetable_cache
value in your configuration file. You'll find a balance by experimenting with these variables during peak times. You want to configure it so that at peak times, there are a low amount ofopened_tables
even after the server has been up for a long time.key_buffer_size
is also a good variable to experiment with. This variable affects the index buffer size, and making this variable bigger increases MySQL's index handling speed. You can look at the variables with theshow variables;
command again, and comparekey_read_requests
tokey_reads
. Ideally, you want the ratio between these two variables to be as low as possible, and you can do this by increasing the size of thekey_buffer_size
. If you set this variable higher, you will have less writes and reads directly to and from the disk, which was your main concern.