To find out if MySQL is running on a Linux system, you can use the mysqladmin
command with the ping
option. The syntax is as follows:
mysqladmin ping
This will display a message indicating whether MySQL is running or not.
If MySQL is running, the output will be mysqld is alive
. If MySQL is not running, the output will be an error message indicating that the MySQL server is not responding.
For example, if MySQL is running, the output might look something like this:
mysqld is alive
If MySQL is not running, the output might look something like this:
mysqladmin: connect to server at 'localhost' failed error: 'Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)' Check that mysqld is running and that the socket: '/var/run/mysqld/mysqld.sock' exists!
Alternatively, you can use the systemctl
command to check the status of the MySQL service. The syntax is as follows:
systemctl status mysql
This will display the status of the MySQL service, including whether it is running or not.
For example, if MySQL is running, the output might look something like this:
● mysql.service - MySQL Community Server Loaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset: enabled) Active: active (running) since Sun 2021-01-03 12:34:56 EST; 2h 24min ago
If MySQL is not running, the output might look something like this:
● mysql.service - MySQL Community Server Loaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset: enabled) Active: inactive (dead)