mysql exit codes

Atheus

Diamond Member
Jun 7, 2005
7,313
2
0
This might be better off on a mysql dev forum, but you never know what valuable nuggets of genius might be extracted from AnandTech on any given day, so here goes...

I have a script which checks for the 'too many connections' error and restarts mysql if it finds it. Yes it's a hack, and yes I'm working on a permanent fix, but for now I really need this. Here's the script:

#!/bin/sh

dt=$(date)

mysqladmin ping > /dev/null
if [ "$?" = 1 ]
then
echo "[$dt] down!"
#/etc/init.d/mysqld restart
else
echo "[$dt] up"
fi

exit 0

As you can see I rely on mysqladmin giving an exit code of '1' when it encounters too many connections. This works on an older server with an older version of mysql, but on this new server it appears to return '0', regardless of too many connections.

Any ideas on a command I can run that will return '0' for a working mysql server and '1' for too many connections?