First of all check whether MySQL is running or not using the following command:
ps uax | grep mysql
If MySQL is running then, find the location of the socket file created by MySQL. Most probably it will be at “/var/lib/mysql/mysql.sock“. But when PHP communicates with MySQL server in the same host, it uses a socket file and looks for it at “/tmp/mysql.sock“.
Hence to fix the issue, create a symbolic link between these two socket files using the following command.
ln -s /var/lib/mysql/mysql.sock /tmp/mysql.sock
This will fix the issue.