Monitoring: What does mysqladmin ping report?

I'm trying to monitor whether our mysql server is up. The command I'm using for this is:

mysqladmin ping

It will return the following:

mysqld is alive

Does this just check whether the process is currently running or does it also check whether the server is accepting connections?


Solution 1:

"mysqladmin ping" attempts to connect to the chosen MySQL server. The actual server can be specified with the -h option (e.g. mysqladmin ping -h db.example.com), defaulting to localhost.

If the server responds (even with an access denied or similar message), the server is assumed to be alive and "mysqladmin ping" exits with code 0.

Otherwise, the server is assumed to be down and "mysqladmin ping" exists with code 1.

Solution 2:

If you want to be certain that your MySQL server is up, the best thing to do is to write a small script to execute:

SELECT "1";

Your user for connecting would need at least USAGE permission. This won't tell you if there are any problems with your database tables, but your application monitoring will probably tell you this.

It's entirely possible that this is what mysqladmin ping does anyway.