Can’t connect to local MySQL server through socket

by irms

CAUTION: Very nerdy stuff below. Non-nerds need not continue.

Cant connect to local MySQL server through socket geek

Short answer: Check your disk space.

Problem

If you’ve ever had this error:

Warning: mysql_connect(): Can’t connect to local MySQL server through socket ‘/var/run/mysqld/mysqld.sock’

or it’s command line cousin:

ERROR 2002 (HY000): Can’t connect to local MySQL server through socket ‘/var/run/mysqld/mysqld.sock’

You’ll know that googling the problem turns up a number of suggestions to recreate the symlink or to reinstall MySQL.

Solution

For me, the problem was disk space. One of my log files was HUGE and MySQL wouldn’t start because of it. So I just had to locate the offending file, get rid of it, and MySQL fired right up.  If you’re running Ubuntu you can do a little du -s -m * to see a listing of files in any directory that’ll have the file size (in MBs) right next to the name. Starting at the root, you can pretty quickly see which directories are too  large for their own good, and drill down to the problem file. (Mine was a 8.1 GB file [8149 MB], and the slice I was working on had 10GB total space.)

Who knows, maybe this’ll help someone one day.