Edit3: Thanks for the help everyone. Sorry for wasting anybody's time, but it seems like a simple reboot solved it. I should've known better, but I just had the assumption that the "restart" solution is mostly valid just for MS Windows (no offense). I'll keep this in mind before I ask a question here again.

I installed the mysql-client-5.0 and mysql-server-5.0 packages on Ubuntu 8.04, using sudo apt-get install.

When I try to run the "mysql" command, I get the following error:

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

To verify that mysql server is running, I tried this, and it does seem to be running, with the correct socket too:

$ ps aux | grep mysql
root     13388  0.0  0.0   1772   528 ?        S    06:24   0:00 /bin/sh /usr/bin/mysqld_safe
mysql    13553  0.0  1.4 127012 15332 ?        Sl   06:25   0:00 /usr/sbin/mysqld --basedir=/usr --datadir=/var/lib/mysql --user=mysql --pid-file=/var/run/mysqld/mysqld.pid --skip-external-locking --port=3306 --socket=/var/run/mysqld/mysqld.sock
root     13555  0.0  0.0   3008   696 ?        S    06:25   0:00 logger -p daemon.err -t mysqld_safe -i -t mysqld
ehsanul  16910  0.0  0.0   3092   772 pts/4    R+   07:17   0:00 grep mysql

So I don't understand why I'm getting an error trying to connect to mysql server. Note that I'm completely new to mysql.


As requested in comments, the exact command that is returning the error is simply "sudo mysql".
And when I check netstats for active networks services, I do see an entry for port 3306, with Protocol: tcp, IP Source:, State: LISTEN

Edit2: It appears as if the /var/run/mysqld/mysqld.sock socket doesn't exist (if I'm interpreting the following output correctly):

$ ls -al /var/run/mysqld/
total 0
drwxr-xr-x  2 mysql root  40 2009-08-06 06:36 .
drwxr-xr-x 20 root  root 860 2009-08-06 06:25 ..

4 Answers 4


If you are having problems connecting through socket, you may try connecting to your mysql server via tcp:

mysql -h localhost

Or using username/password:

mysql -h localhost -u root -p

Either one may work depending on how the users are set up. If you get this error it means that the mysql command is at least talking to the server:

ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
  • Thanks, but I get the exact same error, referring to the same socket. The socket connection is over tcp anyways, and netstats shows it.
    – ehsanul
    Aug 6, 2009 at 13:09
  • I see your ended up fixing it via reboot; but using the -h option should force mysql client to use TCP rather than socket for the connection. Aug 7, 2009 at 14:54

I've run into this problem with assuming the wrong the place for the sock file when I'm using client software that wasn't compiled with the same options as the server. (in my case, a binary distribution of PHP).

I'd first check to make sure that the client that's being run is actually the one you think you installed, and not some other version lying around.

If that's not it, you can either tell the server to write its socket file in the location the client's looking for it. In my.cnf's '[mysqld]' section, change or add:


or, just put in a symlink. For my PHP problem, as it looks for it in /tmp, I've got a job that runs at startup to add the symlink.


I encountered such problems in the past, usually it comes down to the socket file not being writable/readable by the mysql user. Could you ls -al the /var/run/mysqld/ directory and check the mysqld.sock access rights.

Try: chown mysql:mysql /var/run/mysqld/


chmod 755 /var/run/mysqld/

and then

/etc/init.d/mysql restart

It should fix your issue.

[Edit2] Could you check the my.cnf, especially the socket path and the bind address and report back. The bind address should be and the socket path should be the same.

  • I followed your instructions, but the problem has not changed at all. I get the same error message, and the output of "ls -al /var/run/mysqld/" is still the same, as noted in edit2 of the question.
    – ehsanul
    Aug 6, 2009 at 13:44
  • I've tried to "su root" as well as "su mysql" and then run the "mysql" command, but it's the same. I've also tried "mysql -u root -p", but that also gives the same error.
    – ehsanul
    Aug 6, 2009 at 13:55
  • have you just set up the mysql server or did you encounter the issue after rebooting ?
    – olefebvre
    Aug 6, 2009 at 13:56
  • just a quicky. When you ran the "sudo /etc/init.d/mysql restart" did it output anything ?
    – olefebvre
    Aug 6, 2009 at 13:59
  • I just set it up, and have been troubleshooting since. I'll try rebooting. The restart command did give output, seemed to work. But I try it again now, and it seems starting the server is failing: sudo /etc/init.d/mysql restart * Stopping MySQL database server mysqld [ OK ] * Starting MySQL database server mysqld [fail]
    – ehsanul
    Aug 6, 2009 at 14:06

If it's OpenSuse or SLES, I bet it's AppArmor causing the issue. Go into yast and disable it.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .