MySQL server is usually connected by using the following command
mysql –u root –p
some times we may encounter the following the error
can’t connect to local MySQL server through socket /var/lib/mysql/mysql.sock
A socket is used to bridge connection between the server and client.
Error message explains that it is not able to find that socket file.
Socket file is automatically created when we start the MySQL server and disappears automatically when the server is stopped.
This problem most probably arises when you accidentally delete it or if you reinstall same server again or because of server might not be running currently.
Current running state of the server could be known using the following command
service mysqld status
Use the following command to solve the issue
sudo /etc/init.d/mysqld restart
The above command is used to restart the MySQL server so that the socket file can be created.