Another article for explaining on several alternatives as methods on checking MySQL service state in a host, server or workstation.
Before anything can be done for connecting or performing several operations on the database exists in MySQL Database Server, it is needed to check the status of MySQL Database Server itself.
Knowing that MySQL service is running or not, it will be an advantage to be used for so that time for troubleshooting in order to connect to the PostgreSQL Database server can be evaded.
In the first step, it is important to detect whether MySQL Database Server has already installed or not and the installation process can be skipped when MySQL Database Server itself has already exists as a fully functioning installation. It already ensured that it really has. To make sure whether it has already installed, for an example it can be done by executing ‘apt’ command. The usage of the command itself can be looked further in the article titled ‘List Installed Program in Ubuntu Linux using apt command’. The point is the command will only be useful for the operating system which is installed with Debian-variant operating system distribution.
Following after, find out the related service which is responsible for handling MySQL Database Server’s request. There are several ways for accomplishing this task which is looking at service file configuration located in /etc normally but it can be placed on other location depends on the type of Linux operating system installed. Just type the following command :
cat /etc/service | grep 3306
Continue on checking the state of MySQL Database Server, after it has been installed and configured, moreover it is pointed to listen at port 3306, this is actually the output shown if it has been installed when the above command typed in the bash prompt terminal :
user@hostname:~# cat /etc/services | grep 3306 mysql 3306/tcp mysql 3306/udp user@hostname:~#
The service name popped up as the output of the above command is ‘mysql’. Use the service name to check its state for it is active or not by executing the following command :
service mysql status
This is when it is executed in the bash prompt terminal and turned out the service is active :
user@hostname:~$ service mysql status ● mysql.service - MySQL Community Server Loaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset: enabled) Active: active (running) since Sel 2016-09-27 19:27:36 WIB; 3h 16min ago Process: 1207 ExecStartPost=/usr/share/mysql/mysql-systemd-start post (code=exited, status=0/SUCCESS) Process: 1189 ExecStartPre=/usr/share/mysql/mysql-systemd-start pre (code=exited, status=0/SUCCESS) Main PID: 1206 (mysqld) Tasks: 27 Memory: 16.4M CPU: 4.091s CGroup: /system.slice/mysql.service └─1206 /usr/sbin/mysqld Sep 27 19:27:06 hostname systemd: Starting MySQL Community Server... Sep 27 19:27:36 hostname systemd: Started MySQL Community Server. host@hostname:~$
The other method is checking the port used for specifically listening incoming request for MySQL Database Server by typing the following command in the bash prompt terminal :
netstat -tulpn | grep 3306
If MySQL Database Server is running and it is listening on port 3306, the following wll be possible output of the above command execution :
user@hostname:~$ netstat -tulpn | grep 3306 (Not all processes could be identified, non-owned process info will not be shown, you would have to be root to see it all.) tcp 0 0 127.0.0.1:3306 0.0.0.0:* LISTEN - user@hostname:~$
That is several steps which can be executed to find out whether on port 3306, MySQL Database Server is listening for incoming request.