MySQL can stop without warning. One minute your WordPress site loads fine, the next it shows an error page, and you only find out when a visitor tells you. That is why you need to monitor MySQL uptime instead of assuming the database will always be there. A basic check takes minutes to set up, and it turns a silent outage into a message on your phone while you still have time to fix it.
This guide covers three methods: a simple command-line check with cron, an Uptime Kuma MySQL monitor, and an outside check. You will also learn how to set up alerts, when an automatic restart makes sense, and what to check first when an alert arrives. The steps assume a Linux VPS running MySQL or MariaDB.
Why MySQL downtime hurts more than other outages
When Nginx stops, visitors see an error page. When MySQL stops, the damage spreads further: WordPress cannot load posts, logins fail, and checkouts break. On a small VPS the cause is often simple, the server ran out of memory, the disk filled up, or a heavy query crashed the database. The fix is often quick, but only if you notice in time.
A site that stays down for hours loses traffic and trust. If your site depends on MySQL, the WordPress database connection error is the message your visitors will see, and by then the outage has already cost you something. Monitoring shrinks the gap between the crash and your response from hours to minutes.
What it means to monitor MySQL uptime
To monitor MySQL uptime is to answer three questions on a regular schedule: is the MySQL process running, is it accepting connections, and can it actually answer a query? Each question catches a different failure. The process check catches a crash. The port check catches a service that started but is not listening. The query check catches a database that is up but stuck, for example when it has run out of connections.
Good mysql server monitoring covers all three, from a place separate from the database itself. A check on the same server helps, but it tells you nothing if the whole VPS goes down. So combine a local check with an outside one.
Method 1: A five-minute MySQL health check with mysqladmin and cron
The simplest mysql health check uses a tool that ships with MySQL itself: mysqladmin ping. It answers mysqld is alive when the server responds, and it fails when MySQL is down. That failure is what your alert script watches for. Test it by hand first:
mysqladmin ping -u root -p
systemctl is-active mysql
ss -tlnp | grep 3306
The first line checks that MySQL answers. The second checks the systemd service state, and the third confirms something is listening on port 3306. On MariaDB the service may be called mariadb instead of mysql.
Next, turn the ping into a script that messages you when it fails. Save this as /usr/local/bin/check-mysql.sh:
#!/bin/bash
if ! mysqladmin ping -u monitor -p'your-password' --silent; then
echo "MySQL is down on $(hostname) at $(date)" | mail -s "MySQL down" [email protected]
fi
Use a dedicated MySQL user with almost no privileges, not root:
CREATE USER 'monitor'@'localhost' IDENTIFIED BY 'your-password';
GRANT USAGE ON *.* TO 'monitor'@'localhost';
FLUSH PRIVILEGES;
Schedule the script with cron to run every two minutes:
*/2 * * * * /usr/local/bin/check-mysql.sh
Two minutes is a sensible interval for a small site. Before you trust the setup, test it: stop MySQL with systemctl stop mysql, wait for the next cron run, confirm the alert arrives, then start MySQL again. A full disk can stop MySQL just as surely as a crash, so pair this with our guide on how to watch VPS disk space before it fills up and crashes MySQL.
Method 2: Monitor MySQL with Uptime Kuma
If you prefer a dashboard and a history of past outages, Uptime Kuma is a solid self-hosted choice. It runs in Docker, it is free, and it supports TCP port checks, HTTP checks, and notifications through Telegram, email, and Discord. An Uptime Kuma MySQL monitor usually takes the form of a TCP check against port 3306: if the port stops answering, Uptime Kuma marks the monitor as down and sends an alert.
Our guide to installing Uptime Kuma on a VPS with Docker walks through the setup. Once it is running, add a monitor with these settings: type TCP, hostname or IP of your database server, port 3306, and an interval of 60 seconds. Give it a clear name, such as “MySQL production”, so the alert tells you exactly which server is affected.
A TCP check proves the port is open, but it does not prove MySQL can answer a query. For a stronger check, run Uptime Kuma on a second server and point it at a small HTTP endpoint on your main server that runs mysqladmin ping and returns a 200 status only when the database answers. Then set up notifications with our guide to Uptime Kuma alerting with Telegram, Discord, and email notifications. Pick one channel you actually read.
Method 3: An outside check and server metrics
Local checks on the same VPS go blind if the whole server loses power or network. An outside check fixes that: a second VPS or a cheap monitoring service can ping your MySQL port or your website every minute. The check does not need to reach MySQL directly; if your homepage returns a database error, that tells you enough to start looking. Server metrics add context a simple check cannot give. A tool such as Netdata or Zabbix shows memory, disk use, and MySQL connections over time, so you can see a problem building before the crash.
Set up MySQL downtime alerts that actually reach you
An alert has one job: reach a human fast. Think about where you will see it at 3 a.m. For most people that is a phone notification, which makes Telegram or a push service a better pick than email. Email works as a second channel and leaves a record of past outages, but it should rarely be the only one. Keep the message short: which server, which service, and when it went down.
Watch out for alert fatigue: ten messages for one outage will train you to ignore them. Add a short delay before the first alert so a ten-second restart does not wake you, and group repeat alerts instead of sending one per minute. Test the whole path at least once a month.
Should MySQL restart itself when it crashes?
Systemd can restart MySQL automatically. Add Restart=on-failure to the service unit with a short delay, and most crashes will fix themselves in seconds. But an automatic restart can hide a real problem: if MySQL crashes every night from low memory, restarting it each time keeps the site up while the cause stays untouched. The middle ground is to allow the restart and keep the alert. Let systemd bring MySQL back, and let your monitoring tell you it happened. Then look at the logs the same day and fix the cause if it repeats.
When an alert fires: a short checklist
First, check whether the server itself is up by pinging it and opening SSH. If the whole VPS is down, MySQL is not the problem. Second, check the service with systemctl status mysql and the last lines of the MySQL error log, usually at /var/log/mysql/error.log. The log often names the cause: out of memory, disk full, or a corrupt table. Third, check disk space with df -h and memory with free -h. Fourth, restart MySQL and watch the log while it starts. If connections keep failing after the restart, the problem may be connection limits rather than a crash. Our guide to fixing the MySQL too many connections error on a VPS covers the settings that cause that error and how to size them for a small server.
Common mistakes to avoid
The most common mistake is monitoring only the website. A homepage check catches a down site, but it cannot tell you whether MySQL or the web server failed, so check the database directly. The second mistake is monitoring from the same server and nowhere else: that fails silently when the whole VPS goes down. The third mistake is never testing the alert. A monitor that has never fired might have a broken notification channel, a wrong password, or a cron job that never ran, so test it on purpose and repeat the test when you change anything.
Start with the mysqladmin check today, add Uptime Kuma when you have an hour to spare, and put one check outside the server before the end of the week. That combination catches most MySQL outages within a couple of minutes. MySQL will still crash from time to time. The difference is that next time, you will know about it before your visitors do.