Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am running MySQL 5.0.75-0ubuntu10.5 on Ubuntu 9.04 Jaunty. When I try to login as a root to MySQL

# mysql -u root -h localhost -padmin

I get following error

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

But if I try using phpmyadmin http://localhost/phpmyadmin I can login using same credentials.

There are 3 entries for user "root" in mysql.user table with 3 different hosts

  • localhost
  • indrik (hostname)

Encrypted Password for all these 3 entries is identical. I tried all 3 hostnames with -h argument, still no luck.

Any pointers?

share|improve this question

Try connecting to localhost using TCP instead with the following additional command line argument:


You can also make sure you have the correct socket file my checking /etc/my.cnf :


If that states a different socket than the one in your error you can specify it on the command line with --socket=path, i.e. --socket=/var/lib/mysql/mysql.sock.

share|improve this answer
I found out that in /etc/mysql/my.cnf the location of mysql socket was defined as /tmp/mysql.sock but in /etc/mysql/debian.cnf it was /var/run/mysql/mysql.sock. So by providing --socket=/var/run/mysql/mysql.sock as an argument I can login to mysql as a root user. – greenmang0 Aug 18 '10 at 13:40
@greenmang0: You should be able to fix that in the my.cnf under a client configuration header so you don't always have to specify the socket file. – Kyle Brandt Aug 18 '10 at 13:51
Yup I did that. Now it works. Thanks. – greenmang0 Aug 19 '10 at 6:09

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.