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


Enter Your Query:
Use '%' for wildcards and quotes for "exact phrases"


Top Level » MySQL / MariaDB

Warning: mysql_connect() [function.mysql-connect]: Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2) Last Modified: Dec 19, 2010, 6:41 pm
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.
 
Related Helpfiles
Where is my my.cnf?

© 2018 JBMC Software, Suite 173  3-11 Bellerose Drive, St Albert, AB  T8N 1P7  Canada.  Mon-Fri 9AM-5PM MST