Description
If we are managing a MySQL database server, we may get into an issue where the SQL Server is down and not responding.
Moreover, when we try to connect to MySQL Server using a command line, it issues the below error message.
> mysql
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)
Approach #1
First, check the status of the installed MySQL server using the below command.
> systemctl status mysql
Then, try to use the below commands to stop, start and restart the MySQL server, and check if that resolves the issue.
> service mysql stop
> service mysql start
> service mysql restart
And, if the MySQL service is configured to start with the system boot, then use the below commands.
> systemctl stop mysql
> systemctl start mysql
> systemctl restart mysql
Approach #2
If the above approach doesn't work, then follow this approach.
Poweroff the VPS machine using the below command using the command line.
> poweroff
If you are using a VPS machine from a hosting provider (like Digital Ocean, Hostinger, etc.,), then turn off or power off the VPS machine from the respective VPS console.
Then, turn ON the droplet and wait for some time to get the machine up and running.
Once the VPS machine is up and available, then check the MySQL database and other services which must be up and running (if they are configured to start with the machine). Otherwise try to manually invoke them which must be successful.
Overall
We now know how to resolve the commonly occurring MySQL database startup issue.