MySQL MariaDB

How to Find out if MySQL is Running on Linux or Not

MySQL is a popular RDBMS available for multiple operating systems. Moreover, specifically, It can be used in the Linux operating system for various essential tasks like database administration and many more. To perform all those tasks, the user needs MySQL in running condition. There are various methods to find if MySQL is running on the system or not.

This post will discuss methods:

Prerequisite

To begin with this post, MySQL should be installed in your system. To verify if MySQL is installed in your system or not, use this command:

mysql --version

The output will display the version of install MySQL:

Method 1: Find out if MySQL is Running Using the “systemctl” Command

The “systemctl” command is used to manage and control the services on a Linux system. To find if MySQL is running or not, use this command:

sudo systemctl status mysql

It will show the status of MySQL, here the status is displaying as “Active (running)”:

The “systemctl” command can be utilized to enable, start and stop the service. Let’s run a command to stop MySQL service:

sudo systemctl stop mysql

To verify the status of MySQL now after stopping it, type the status command again, and it will display the status as “inactive (dead)”:

Method 2: Find out if MySQL is Running Using the “ps” command with “grep” Filter

The “ps” command in Linux is used to tell the status of the active processes along with their details. To get the active processes of MySQL, only use the “grep” filter to only specify it. To see if MySQL is running or not, type the command:

ps -aux | grep mysql

The output will display all the processes related to MySQL only if it is running:

To only get the process id of a specified service, use the “pgrep” command. Let’s run the “pgrep” command for MySQL:

pgrep mysql

The output will display the process id of MySQL if it is running in the system:

Let’s run the same command after stopping the MySQL service to see if the “pgrep” will show any output or not:

The output is not displaying any result which means MySQL is not running.

Method 3: Find out if MySQL is Running Using “mysqladmin” Command

The “mysqladmin” is an administrative client tool used to check the server configurations. To check the status of MySQL use this command:

sudo mysqladmin -u root -p status

The output is displaying the “Uptime” which means MySQL is in running on Linux:

Let’s see what would be the result if MySQL is not running:

You can also find out if MySQL is running or not by typing:

sudo mysqladmin -u root -p ping

The output is display “mysqld is alive” which means MySQL is running:

This would be the output if the MySQL is not running on Linux:

Alternatively, this given command can also perform the same operations:

sudo service mysqld status

You learned different methods to find out if MySQL is running on Linux or not.

Conclusion

Use different methods to see if MySQL is running on Linux or not. The first method is to run the “sudo systemctl status mysql” command. For the second method, use the “ps -aux | grep mysql” command. The third method is to run the “sudo mysqladmin -u root -p status” or “sudo mysqladmin -u root -p ping” command. This post provided different methods to check if MySQL is running on Linux or not.

About the author

Abdul Mannan

I am curious about technology and writing and exploring it is my passion. I am interested in learning new skills and improving my knowledge and I hold a bachelor's degree in computer science.