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

This post is CENT OS based:

You got this error:

Warning: mysql_connect(): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock'

Simple troubleshoot:

  1. Goto /var/lib/mysql/ (or locate mysql.sock othervise)

  2. Delete mysql.sock

  3. Restart mysql via service mysqld restart

PS. Don’t forget to updatedb to get the locate most accurate.

If you cannot find the socket path [socket=/var/lib/mysql/mysql.sock] get the path from this command:

vi `locate my.cnf | awk '{if (1==NR) print $0}'`

tags: & category: -