Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

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 just installed the MySQL-client-5.5.24-1.el6.x86_64.rpm.

I'm trying to connect to a database on a different machine but when I run "mysql" I get an error:

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

Any idea how to run the mysql client (without the server running)

share|improve this question
up vote 4 down vote accepted

Specify the host:

mysql -h host ...

See man mysql for all options.

share|improve this answer

You didnt tell it where to connect to. You need to use '-h host' or '-h server.ip.add.ress'

 mysql -h host -u <username> 

(and add -p if you have password set up)

share|improve this answer

Use different commandline options to specify the remote MySQL server you want to connect to.

-h servername

-u username

E.g. mysql -h -u username -p database

-p specifies that you will enter your password from the commandline right after connecting to MySQL.

You can also add your options in a configuration file.


user = dbuser
pass = dbpass
host =
default-character-set = utf8

And then connect to MySQL with the following command:


Or to a specific database:

mysql <database>

share|improve this answer
If you call your file .my.cnf you won't need --defaults-extra-file=~/ – Ladadadada May 30 '12 at 10:13
Good call, I have many mysql-servers I connect from so I normally use the --defaults-extra-file options. – pkhamre May 30 '12 at 10:42

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.