Some words to the wise.
For quite a period of time, I suffered from regular mySQL crashes. I therefore did the unthinkable, and poured over
http://www.mysql.com/doc/S/H/SHOW_VARIABLES.htmlA few basic lessons learned, for beginners like me.
Inside mySQL, you can run
> show variables;
to display the current variables in action. And you can run
> show status;
to see the impact of these variables & gauge the current state of your mySQL installation.
Your my.cnf file, usually sitting in /etc/ , controls the default settings for many of the variables. In the source of mysql, there are several default my.cnf files... one for small systems, another for medium and large.
Persistent database connections put a lot of demands on memory... generally not worth the small speed improvement.
A few key parameters to adjust:
key_buffer_size
This one is really important. It's explained well in the manual. What's not stressed enough is that if you set this value to be too large, mySQL will demand memory from your operating system. If this demand is too high, Your OS will attempt to accommodate the request, leading to swapping/paging and your system will slow down to a crawl. This is what was happening to me. Also, don't be fooled by the seemingly available memory reported by the OS. I suspect that Linux doesn't like giving too much memory to a single app... so although Linux might report free available memory, you might still be swapping.
To adjust key_buffer_size, take a look at the status results... if Key_reads compared to Key_read_requests is about 1%, you're doing OK... no need to increase key-buffer_size further. A value of 32 MB is quite sufficient in most cases, and 64 MB is very generous.
table_cache
This is probably the next most important value. I have it set to 128. If it's too small, you'll see your "Opened tables" value steadily grow bigger when running status. If "Opened tables" is steady, you don't need to increase this value (but try decreasing it to see if you can get away with less).
thread_cache_size
Try setting this to 8 if you have enough memory. The impact of a larger number is that your ration of "threads created" to "Connections" will decrease. I believe that CPU demands will also decrease. This variable is important if you have a lot of short-lived connections, but is less important otherwise.
thread_concurrency
The manual recommends setting this to # of CPUs x 2. It mentions that it only matters on Solaris, but I'm not certain... to play it safe, don't exceed the CPU x 2 number.
max_connections
100 is common. I have it set to 50, on a forum which frequently has 50+ simulataneous users. You really don't want too many simultaneous queries hitting mySQl at the same time... bad things can happen. I'd rather have a user get an error message every once in a long while, and have to hit reload, than to have mySQL crunch, creak and buckle. This is especially important if you're suffering from frequent crashes / slowdowns. A common mistake is to increase the number of connections... you should decrease them instead.
OK, that's pretty much my current braindump with respect to mySQL optimisation... not much for experienced users, but I hope that it's useful for someone out there. Please feel free to ask questions, or correct any errors I may have made.
Regards,
Max