Designing a well structured, normalized database schema is just half of the optimization task. The other half is building and fine tuning a server to run MySQL. MySQL provides a wealth of information regarding the tuning of server parameters. This information which was traditionally accessible in a configuration file called my.cnf, but can now be accessed and tuned visually using the MySQL Administrator graphical interface.
MySQL default parameters are very small so it can run on almost any box as an additional service without slowing things down. MySQL provides my-small/medium/huge.cnf files that come with the standard binary distribution as general parameter guidelines for small, medium, and huge servers.
Many of the optimal parameter values will depend a lot on the load you put on the server, as well as the storage engines(s) you use. But, here are some generic guidelines to optimize performance regardless of which storage engine you are using. We will take a look at storage engine specific tuning options in a future article so please, continue to watch this space.
Set max_connections to the number of concurrent connections you need. The default value is only 100 connections, which is very small.
Note: connections take memory and your OS might not be able to handle a lot of connections. MySQL binaries for Linux/x86 allow you to have up to 4096 concurrent connections, but self compiled binaries often have less of a limit.
Set table_cache to match the number of your open tables and concurrent connections. Watch the open_tables value and if it is growing quickly you will need to increase its size.
Note: The 2 previous parameters may require a lot of open files. 20+max_connections+table_cache*2 is a good estimate for what you need. MySQL on Linux has an open_file_limit option to set this limit.
If you have complex queries sort_buffer_size and tmp_table_size are likely to be very important. Values will depend on the query complexity and available resources, but 4Mb and 32Mb, respectively are recommended starting points.
Note: These are "per connection" values, among read_buffer_size, read_rnd_buffer_size and some others, meaning that this value might be needed for each connection. So, consider your load and available resource when setting these parameters. For example sort_buffer_size is allocated only if MySQL nees to do a sort. Note: be careful not to run out of memory.
If you have many connects established (i.e. a web site without persistent connections) you might improve performance by setting thread_cache_size to a non-zero value. 16 is good value to start with. Increase the value until your threads_created do not grow very quickly.
