Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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 the the MySQL is using only 250MB of RAM, keeping the disks very busy, even though I have plenty of freee ram laying around.

I SQL Server I can easily set the amount of mememory 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?

share|improve this question
add comment

2 Answers

up vote 7 down vote accepted

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.

share|improve this answer
1  
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
add comment

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.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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