Can’t connect to local MySQL server through socket ‘/var/lib/mysql/mysql.sock’

The error Can’t connect to local MySQL server through socket ‘/var/lib/mysql/mysql.sock’ can be caused by several things. Here are some steps to take to fix it.

1. The mysql server is not installed. 

“But wait” you say ” I just installed it”.  Most likely you did a yum install mysql If that is the case then you did install the mysql client, but not the server.

To fix the issue on fedora enter as root

yum install mysql mysql-server

or on ubuntu as root

apt-get install mysql mysql-server

You should be able to start the mysql service. There different ways to start services depending on your distribution of linux. One of these should work.

service mysqld start (notice that there is a d at the end of myqsl. Stands for mysql daemon)

or

/etc/init.d/mysql start
If you still have problems, logout or reboot and try again.