Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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
add comment

3 Answers

up vote 4 down vote accepted

Specify the host:

mysql -h host ...

See man mysql for all options.

share|improve this answer
add comment

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
add comment

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

-h servername

-u username

E.g. mysql -h server.example.com -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.

~/.my.cnf

[client]
user = dbuser
pass = dbpass
host = mysql.example.com
default-character-set = utf8

And then connect to MySQL with the following command:

mysql

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=~/.mysql-client.cf. –  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
add comment

Your Answer

 
discard

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.