Here is the source code of the MySQL Server Crash Monitor.
// Change the e-mail address below .
$from = "[email protected]";
$to = "[email protected]";
$subject = "MySQL Crashed!";
$body = date("Y-m-d H:i:s");
$headers = 'From: '.$from . "\r\n"
.'Reply-To: '.$from . "\r\n"
.'X-Mailer: PHP/' . phpversion();
mail($to, $subject, $body, $headers);
// Log to file
$filename = 'log.txt';
$somecontent = date("Y-m-d H:i:s");
$somecontent = $somecontent . "\r\n";
if (is_writable($filename)) {
if (!$handle = fopen($filename, 'a')) {
exit;
}
if (!fwrite($handle, $somecontent)) {
exit;
}
fclose($handle);
}
First, upload a file named log.txt to the WordPress root directory, chmod it to 666.
Second, replace the e-mail address of the code to your own e-mail.
Then,opening wp-includes/wp-db.php, find "if (! $ This-> dbh)", 66 lines in WordPress 2.3.1, paste the code after that. Save and upload the file.
Now, When the database lost connection or get problems, WordPress will automatically mail the error message to your mailbox, at the same time the message will be recorded in log.txt document.