6

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?

3 Answers 3

8

"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.

4

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.

1
  • 1
    You can instead use mysqladmin status, which only requires a valid user, without needing any permissions, and will be able to determine whether or not the server is usable without the false positive that ping sometimes gives. It also follows that selecting, and whatever ping does, is not the same.
    – swalog
    Feb 15, 2019 at 12:44
2

"up" is very broad term. E.g. it may respond to ping, but actually have no free disk space, or all queries are blocked or crashing every second and automatically restarting, or all tables are actually marked as crashed or even worse - dropped or datadir got unmounted from the system etc.

Or it can be swapping like crazy and CPU is abused by several queries, so it can hardly crawl, so it is not "up" for sure.

Or e.g. it may fail to respond to ping e.g. because of connection limit, but your applications use persistent connection and work perfectly.

Or e.g. it may fail to respond to ping e.g. because of some client problem on localhost, but again - all applications do not actually experience any issue.

So, sometimes 'ping' is valid answer, but you need always consider these cases while thinking about "monitor whether server is up".

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .