This post will discuss methods:
- To Find out if MySQL is Running Using the “systemctl” Command
- To Find out if MySQL is Running Using the “ps” command with the “grep” Filter
- To Find out if MySQL is Running Using “mysqladmin” Command
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:
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:
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:
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:
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:
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:
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:
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:
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.