How to increase memory usage in MySQL Server to improve speed?
Solution 1:
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.
Solution 2:
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.