Linux – ERROR 2002 (HY000): Can’t connect to local MySQL server through socket ‘/tmp/thesql.sock’ (2)

linuxMySQLunix

Can someone please help as i've spent all day trying to fix this. I installed the latest XAMPP and now i can't connect to mysql from terminal.I checked my .profile file and the PATH seems ok. Does anyone know whats happened and what's the solution?

PATH=$PATH:/Applications/XAMPP/xamppfiles/bin export PATH

THIS IS A PROGRAMMING QUESTION AS I'M A PHP DEVELOPER TRYING TO DO MY JOB!

Thankyou soo much in advance;-)

UPDATE: the solution was to update the .bash_profile with (as well as the .profile file)

PATH=$PATH:/Applications/XAMPP/xamppfiles/bin
export PATH

spent the whole day trying to work this out so i hope this helps anyone in the same position 😉
http://www.jroller.com/jnicho02/entry/setting_up_xampp_on_the (GOOD LINK)

Best Answer

This can be one of two problems -- mysql isn't running, or mysql isn't putting the socket file in /tmp.

If the mysql command line program works, then the database is up, and it's just that php is compiled w/ the wrong location for the socket file. If it were in any other place, you'd get by with just adding a symlink from the place PHP is looking to the correct place, but because /tmp is cleared on reboot, you'll either need to change the my.cnf to write it to /tmp (possibly breaking other things), or you'll need to re-compiled PHP w/ the option for it to look in the right place, or you can add the following to cron:

@reboot ln -s /var/mysql/mysql.sock /tmp/mysql.sock

... adjusting /var/mysql/mysql.sock for wherever the correct location is.

If mysql isn't running, the common problems are either that it's not set to launch after reboot, or it's run into some error. Check the error logs for any information, and if there's nothing in there since the last reboot, you'll need to do whatever your flavor's preferred method is to set it to start on reboot.