Mysql – Access thesql remote database from command line


I have a server with Rackspace. I want to access the database from my local machine command line.

I tried like:

mysql -u username -h -ppassword

But it gives an error:

ERROR 2003 (HY000):

Can't connect to MySQL server on '' (10061)

What causes this error and how can I connect to the remote database?

Best Solution

To directly login to a remote mysql console, use the below command:

mysql -u {username} -p'{password}' \
    -h {remote server ip or name} -P {port} \
    -D {DB name}

For example

mysql -u root -p'root' \
        -h -P 3306 \
        -D local

no space after -p as specified in the documentation

It will take you to the mysql console directly by switching to the mentioned database.