Gossamer Forum
Home : Products : Gossamer Links : Version 1.x :

I need to restart MYSQL

Quote Reply
I need to restart MYSQL
How do you restart MySQL on UNIX.
Quote Reply
Re: I need to restart MYSQL In reply to
On solaris (I'm not sure about other Unices) I think I started it at a run level that the system monitors and restarts automatically if it dies, just like sendmail and some other processes. You'd need to consult your user manual for your Unix version about 'run levels' and start-up commands.

Looking at the script, I'm assuming you'd be using this as a 'start up' script? Then having the system run this script like cron, making sure this script doesn't die?? <G>??

Gets sort of complicated.



Quote Reply
Re: I need to restart MYSQL In reply to
If you have a dedicated server, you use the same command you used to start it.

If you are not on a dedicated server, you can't restart it. Your ISP will have to.

If mysql is running locally, you can

cd /usr/local/mysql
./bin/safe_mysqld &

that should start it.

Quote Reply
Re: I need to restart MYSQL In reply to
It worked, Thanks :-)

You are a life saver.
Quote Reply
Re: I need to restart MYSQL In reply to
It's worthwhile having a monitor script to restart mysql if it ever dies. We use something like:

Code:
my $debug = 0;
my @dbi = ('DBI:mysql:test', '', '');
my $admin = 'you@yourserver.com';
my $mail = '/usr/sbin/sendmail -t';
my $pid_file = '/usr/local/mysql/data/mysql.pid';

print "Checking mysql ... \n" if $debug;
my $dbh = DBI->connect(@dbi);
if (! defined $dbh) {
print "failed.\n" if $debug;
print "trying to restart ... \n" if $debug;
&resurrect_mysql ($DBI::errstr, $my_pid, $my_start, $mail, $admin);
print "ok.\n\n" if $debug;
}
else {
print "ok.\n\n" if $debug;
$dbh->disconnect;
}

sub resurrect_mysql {
# -----------------------------------------------------------
my ($message, $pid_file, $my_start, $mail, $admin) = @_;

# Open Mail and redirect stderr to mail.
open (MAIL, "| $mail") &#0124; &#0124; die "mail: $!";

# Change to mysql.
chdir ("/usr/local/mysql") or die "chdir: $!";

my $date = localtime();
print MAIL <<END;
To: $admin
From: The Watchful Server Monitor <nobody>
Subject: Mysql server is down!!

I tried to connect to mysql on $date
but there was no answer! Error Message was:

$message

I am going to try to resurrect it now:

END
;
my $pid = `cat $pid_file 2>/dev/null`;
my $output = '';
if ($pid) {
print MAIL "Found pid $pid .. killing... ";
print MAIL `kill $pid`;
print MAIL "Done.\n\n";
}
eval {
local $SIG{ALRM} = sub { die "alarm\n" };
alarm(3);
$output = `$my_start 2>&1`;
alarm 0;
};
$@ ?
print MAIL "\nStartup Timed out! Output: $output\n\n" :
print MAIL "\nOutput: $output\n\n";

print MAIL <<END;

That's the best I could do. Hope it helped.

The Web Monitor
END
close MAIL;
}

Note: This assumes mysql is in /usr/local/mysql, you might need to alter if you've installed via RPM's.

Cheers,

Alex
Quote Reply
Re: I need to restart MYSQL In reply to
Yes, this is run every two minutes in cron(and is actually just a snippet of the full one -- it also checks the mod_perl server, webserver, qmail, etc).

The advantadge of this, is that it mimics an actual request, where most other just monitor that the process is still running. That way if mysql hangs, or is unresponsive, the monitor script will restart it.

The only downside right now is if it dies in the night and can't restart it (only happened once) I end up with 400-500 emails in the morning. Wink

Cheers,

Alex