Add to Favourites Add to Favourites    Print this Article Print this Article

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

If you get an error that you cannot connect to your mysql.sock file (can also be /tmp/mysql.sock on FreeBSD/Debian), then do the following:


1) check to see if the mysql.sock exists:

ls -la /var/lib/mysql/mysql.sock



2) check to see if it's some other mysql instance that has moved it somewhere else (possibly from a wrong my.cnf setting):

netstat -lnp | grep mysql



3) check to see if it's mysqld is running:

ps ax | grep mysql



3) Resart mysqld to recreate the sock file:

/etc/init.d/mysqld stop
/etc/init.d/mysqld start



4) If needed, use a brute force method (as a last resort):

killall -9 mysqld mysqld_safe
killall -9 mysqld mysqld_safe

repeat until no mysqld process is running, it will throw an error.
Then type:

/etc/init.d/mysqld start



5) check /var/lib/mysql/`hostname`.err for clues.   On FreeBSD/Debian, it's /home/mysql/`hostname`.err.

Was this answer helpful?

Also Read