How to Check the Status of MySQL

JUNE 17, 2024 • WRITTEN BY ROMAN AGABEKOV
To check MySQL status on a Linux host using systemd, start with systemctl status mysql (or the installed service name, such as mysqld). Then check whether your intended server answers and whether you can log in and run a query. A running service does not guarantee a working database connection.

The checks below distinguish service state, endpoint reachability, authenticated SQL execution, and status metrics. They do not change MySQL settings. The client examples use MySQL 8.4 syntax; service names and log locations depend on your installation.

How to Check If MySQL Is Running

On Linux systems using systemd, the command below reports the state of the MySQL service on that host. Use the installed service name; it may be mysql or mysqld. A running service or a visible mysqld process does not prove that clients can connect or execute SQL.
systemctl status mysql
Look for the service state, such as active (running), inactive, or failed. If the unit is not found, verify the installed service name. On systems that provide the service wrapper, this is an alternative status command:
sudo service mysql status
On Windows, open Command Prompt and list running services with the following filter:
net start | findstr "MySQL"
This Windows command lists running services whose displayed names match the filter. No match does not by itself prove MySQL is stopped; service names can differ.

Is the client installed?
Running mysql --version reports the client version if the executable is available. It does not prove that a server is installed or running. A command-not-found error can also mean the client is not on PATH.

Does the intended server answer?
With the MySQL client tools installed, replace DB_HOST, DB_PORT and DB_USER with your intended TCP endpoint and an authorized account. Keep the required TLS options for your environment; enter the password at the prompt, not on the command line.

mysqladmin --protocol=TCP -h DB_HOST -P DB_PORT -u DB_USER -p ping

mysqld is alive indicates that the server answered. Even an Access denied response can produce exit status 0 from mysqladmin ping: the server answered, but authentication was rejected. A connection error requires checking the endpoint and connection path, not an automatic restart.

Can you authenticate and execute SQL?

mysql --protocol=TCP -h DB_HOST -P DB_PORT -u DB_USER -p --execute="SELECT 1;"

A successful result containing 1 confirms that this connection authenticated and executed a constant query at that moment. It does not test application-table access, writes, replication, or workload performance. These examples test TCP, not a Unix socket connection. See the mysqladmin manual for the ping behavior.

How to Troubleshoot the Problem if MySQL is Not Running

If MySQL isn't running, you can take several steps to troubleshoot and get it back up and running.

1. Check the Existing Error Log

If the service failed to start or stopped unexpectedly, inspect the existing error log and service messages. Record the reported error before taking action; it is more useful than guessing from a failed connection alone.

2. Identify Which Check Failed

Separate an inactive service from an unreachable endpoint, a rejected login, or a failed query. One failed client check is not a reason to restart MySQL. Use the reported error and existing service or error-log information to decide the next step with the database owner.

3. Verify the Configuration Files

Compare the startup error with the configuration actually used by this server. A file named my.cnf or my.ini is not necessarily the active configuration. Do not change paths, permissions, or settings based only on a failed connection.

4. Check Disk Space

Check free space on the volumes holding MySQL data and logs. Low free space can explain write or startup failures, but do not delete database files to make room. Ask the database owner to choose a safe remediation.

How to Check MySQL Server Logs

  • Start with the existing error log when investigating startup or shutdown problems. General and slow query logs answer different questions; enabling them is not required to check whether MySQL is running.

Checking the Error Log

The error log records startup, shutdown, and diagnostic messages. Its destination is installation-specific. The command below is only an example for a Linux installation that already writes to /var/log/mysql/error.log; use the configured destination and authorized log access.
 sudo cat /var/log/mysql/error.log
On Windows, use the error-log location configured for your instance or supplied by its administrator. Do not assume it is under Program Files. For managed databases, use the provider's log viewer rather than a local server path.

Checking the General Query Log

If already enabled, the general query log can help inspect connection activity and statements received by the server. It is not proof that a statement succeeded. Do not enable logging or change its destination merely to check server status; logging can add overhead and capture sensitive SQL.

Checking the Slow Query Log

An existing slow query log can help investigate slow queries under the server's configured logging rules. An empty log does not prove that the workload is healthy: the log may be disabled or the statements may not meet its criteria. Choosing thresholds or enabling the log is a separate operational change.

Before Starting or Stopping MySQL

Starting, stopping, or restarting MySQL changes availability; these are maintenance actions, not status checks. A failed login or slow query alone is not a reason to restart the server. Use the observed service state, connection error, and existing logs to agree on the next action with the database owner.

Verifying Configuration Files

  • MySQL can read more than one configuration file. Confirm the option files and startup arguments used by the specific instance with its administrator. A similarly named file found elsewhere on the host may not control this server.
For a startup failure, compare the error message with the configured data directory, socket, port, and permissions. Inspect first; do not edit configuration or change ownership as part of a basic status check.

Checking Disk Space

  • On Linux/Unix, the command below reports filesystem space. Identify the mounted filesystems that hold this instance's data and logs; free space on an unrelated volume does not answer the question.
df -h
On Windows, inspect free space on the volumes holding the instance's data and logs using File Explorer or Disk Management.
Available disk space is one check, not a database-health verdict. If space is low, share the observation with the database owner; do not remove MySQL data or log files without an approved procedure.

What Are MySQL Status Variables?

SHOW STATUS returns status variables, not a healthy or unhealthy verdict. Without a scope modifier it defaults to SESSION; SHOW GLOBAL STATUS requests global status values. Interpret each variable in its documented scope. Cumulative counters are not current rates; account for restarts and resets. A successful status query does not establish application performance or replication health.

Read-only queries still consume resources. See the MySQL SHOW STATUS manual and the MySQL Server Status Variable Reference.

For ongoing observation beyond a one-time status check, explore Releem MySQL Monitoring.

Article by

  • Founder & CEO
    Roman Agabekov has 17 years of experience managing and optimizing MySQL and MariaDB in high-load environments. He founded Releem to automate routine database management tasks like performance monitoring, tuning, and query optimization. His articles share practical insights to help others maintain and improve their databases.