How often should Apache and MySQL be restarted (in particular having 150K hits/week), and what would be the actual benefit in restarting every certain time?


If your system is properly tuned and your application doesn't have any issues like memory leaks, you should only ever have to restart them to apply patches.


Apache and MySQL by themselves should be free of memory leaks. Most databases servers run better the longer they have been up. However, modules which are compiled into Apache like PHP often have memory leaks.

The Apache mpm module automatically recycles processes after 10,000 requests. You can change the MaxRequestsPerChild to something different, but 10,000 is a reasonable default.

  • What does this mean: Most databases servers run better the longer they have been up? What does better mean? – tshepang Jul 19 '11 at 22:57

Apache does not need regular restarting; nor should MySQL.

Apache running in prefork mode can recycle its child processes using MaxRequestsPerChild; this is a good thing as it defends against slow memory leaks, etc.

MySQL should not be restarted regularly, as restarting it will cause a service outage. Restarting MySQL needs to wait for the engines to start up and will also clear out the cache causing performance to suck until it warms up. We seem to find that it needs restarting from time to time[1] because of address space fragmentation, but this should not happen so much on a 64-bit system, which new installations should always go on to.

[1] e.g. every 9 months on a busy server with > 100 queries per second average


You should avoid restarting MySQL whenever possible for performance reasons. MySQL uses lots of memory to cache data pages and indexes. When you restart MySQL, all cached pages are freed and you need some time to warm up caches. On highly loaded sites database restart could cause performance problems.

Your site is not heavily loaded (150k hits/week gives only 1req/4s), so MySQL restart should not cause big problems.


In order to understand when a system or service needs to be rebooted you first need to understand why. Memory leaks are the most common reason but there may be others, such as poorly written software (all too common!) that doesn't perform proper internal housekeeping, such as closing file handles when they are no longer required. While not being the same as a memory leak the symptoms are the same. Both Apache and MySQL are known to be very stable (unless you're running an alpha or beta version) and can run for years without issue. Normally the operating system will need rebooting to apply patches long before either application will require it.

Your Answer

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