brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: mysqladmin ping and status give a quick MySQL health check

Mysql
~/tips/tip-database-mysqladmin-ping-status

mysqladmin -u root -p ping

Checks whether the MySQL server is up and prints a one-line status with uptime, threads and queries.

Sometimes you only want to know whether the database server is alive, without opening a SQL session. mysqladmin does that in one line.

mysqladmin -u root -p ping
mysqladmin -u root -p status

According to the MySQL manual, ping checks whether the server is available, and status displays a short status message. The status line has the uptime in seconds, the number of threads, questions, slow queries, opens, flush tables, open tables and the average queries per second.

ping is the one for scripts, because of its exit code. It returns 0 if the server is running and 1 if it is not:

mysqladmin ping --silent && echo up || echo down

The manual points out that the exit code is 0 even when the answer is an error like Access denied, because a refused connection still means the server is running. A health check in a Docker container or a cron job can use this.

The status output is easy to read and nothing else. For a closer look at what is running, use mysqladmin processlist or the SQL shell.

The caveat is that a good ping says the server answers, not that the application can use the database. A wrong password gives exit code 0 as well, so credentials are not tested by it. For a real check, run a small query with the account your app uses.

Further reading: MySQL manual: mysqladmin

More Mysql tips FOR UPDATE SKIP LOCKED; mysql_config_editor set --login-path=shop \ SET PERSIST max_connections = 300; ALTER TABLE orders ADD COLUMN note VARCHAR(100), ALGORITHM=INSTANT; ALTER USER 'appuser'@'192.0.2.10' All Mysql tips (8) All topics

Link