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 my.application.com
this solution worked for me:
On your remote machine (example: 295.13.12.53) has access to your target remote machine (which runs mysql server)
ssh -f -L 295.13.12.53:3306:10.18.81.36:3306 user@295.13.12.53
Explained:
ssh -f -L your_ssh_mashine_ipaddress:your_ssh_mashine_local_port:target_ipaddress:target_port user@your_ip_address -N
your_ssh_mashine_ipaddress - it is not local ip address, it is ip address that you ssh to, in this example 295.13.12.53
your_ssh_mashine_local_port -this is custom port not 22, in this example it is 3306.
target_ipaddress - ip of the machine that you trying to dump DB.
target_port - 3306 this is real port for MySQL server.
user@your_ip_address - this is ssh credentials for the ssh mashine that you connect
Once all this done then go back to your machine and do this:
mysqldump -h 295.13.12.53 -P 3306 -u username -p db_name > dumped_db.sql
Will ask for password, put your password and you are connected. Hope this helps.
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 127.0.0.1 -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.
There is simple command.
mysql -h {hostip} -P {port} -u {username} -p {database}
Example
mysql -h 192.16.16.2 -P 45012 -u rockbook -p rockbookdb
You should put your password with 'p'
mysql -u root -u 1.1.1.1 -p'MyPass'
I was too getting the same error. But found it useful by creating new mysql user on remote mysql server ans then connect. Run following command on remote server:
CREATE USER 'openvani'@'localhost' IDENTIFIED BY 'some_pass';
GRANT ALL PRIVILEGES ON *.* TO 'openvani'@'localhost WITH GRANT
OPTION;
CREATE USER 'openvani'@'%' IDENTIFIED BY 'some_pass';
GRANT ALL PRIVILEGES ON *.* TO 'openvani'@'%' WITH GRANT OPTION;
FLUSH PRIVILEGES;
Now you can connect with remote mysql with following command.
mysql -u openvani -h 'any ip address'-p
Here is the full post:
http://openvani.com/blog/connect-remotely-mysql-server/