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?


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:

show status;

and have a look for the variable open_tables. If this is the same as your table_cache value, and opened_tables keeps going up, then you need to increase the table_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 of opened_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 the show variables; command again, and compare key_read_requests to key_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 the key_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.

  • 11
    Actually the command is show status; to see status variables such as Open_tables and Opened_tables. table_cache appears to have been removed in recent MySQL versions. – Matt Fenwick Apr 20 '12 at 13:07

You need to change values in the my.cnf file and restart MySQL, although you can change many of them whilst MySQL is running, too ('SET GLOBAL VARIABLE=value').

You will probably want to look at increasing key_buffer_size, sort_buffer, read_buffer and table_cache for starters and probably innodb_buffer_pool_size ,if you have any InnoDB tables. Some of these values you can increase a long way (even two orders of magnitude) especially given your hardware. MySQL's defaults are extremely conservative and seemed to be aimed at common mixed-use desktops of about ten years ago. Oh, and be warned that the 32-bit version will have trouble using more than 2GB of RAM.

Look in the MySQL Manual for more information and guidance.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.