How can I tell when MySQL maintenance is happening?

This page is showing a generic answer.
To see a more detailed answer customized for you, type your domain name here:

Very occasionally, our MySQL database servers may be unavailable due to scheduled maintenance, even when your Web site is otherwise fully active and working.

This happens from time to time with any hosting company; with our company, it usually happens for just a few minutes a year during MySQL version upgrades. We announce this kind of maintenance on our blog and mailing list in advance.

During this kind of maintenance, it can be useful for your script to detect that the database server is temporarily unavailable, even though visitors are still viewing your script. For example, if your script can tell that the database is unavailable, it could display a graceful error message saying that your site is "unavailable due to scheduled maintenance", asking people to try again in a few minutes.

(It's probably a good idea to have your scripts display this kind of user-friendly error message when they encounter any MySQL connection problem, but some people want to be more specific.)

We have a solution for this. During periods when we're performing scheduled maintenance on our MySQL servers, we place a file named "/tigertech-maintenance-mysql" at the top level of the disks on the Web server. Advanced users can make their scripts check for the existence of this file and take appropriate steps.

On the rest of this page:

Checking from PHP scripts

The PHP code to check for MySQL maintenance would look something like this:

if (file_exists('/tigertech-maintenance-mysql'))
{
    /*
     * MySQL databases are unavailable due to scheduled 
     * maintenance; show a graceful error message
     */
    ...
}

Checking from Perl scripts

The Perl code to check for MySQL maintenance would look something like this:

if (-f '/tigertech-maintenance-mysql')
{
    # MySQL databases are unavailable due to scheduled 
    # maintenance; show a graceful error message
    ...
}

Checking from a .htaccess file

If you can't change the "source code" of your scripts, it's possible to add a .htaccess "RewriteRule" to disable certain pages with a redirect during scheduled MySQL maintenance. For example, you could add these lines to a .htaccess file:

RewriteEngine On
RewriteCond /tigertech-maintenance-mysql -f
RewriteRule ^orders/ http://www.example.com/maintenance.html [L]

These lines would make sure that during MySQL maintenance, visitors to any page beginning with:

http://www.example.com/orders/

... would instead be redirected to:

http://www.example.com/maintenance.html

... which would be a custom page you create in advance.