I have the following setup: an RDS instance running in a subnet group of 2 private subnets; an EC2 instance running in a public subnet. So I want to connect to my RDS instance through my EC2 instance.
I want also to be able to connect from shell. So I run the following command on my local computer:
ssh -L 3305:mydb.myrdsinstance.eu-west-1.rds.amazonaws.com:3306 ec2-user@myec2instance
Thus I logged in my ec2 instance and tried to access the database with:
mysql -h localhost -u mydbuser -p
Entered the correct master password and got:
ERROR 1045 (28000): Access denied for user 'mydbuser'@'localhost' (using password: YES)
I also tried tunneling from my ec2 instance (by running the SSH command from it), this also creates connection but I cannot access the database the same as above.
I tried running the ssh command with -N option, this gives a blinking cursor and nothing happens.
The firewall is disabled on my local computer, all traffic allowed both for EC2 and RDS instance.
I also tried to set up connection with Workbench and there is a weird thing going on. When I connect and enter the master password, I am getting "Can't connect to MySQL server on 127.0.0.1 (111)". But if I check "Save password in keychain", next time it connects fine without any changes.
How do I fix this and connect to the RDS instance via SSH tunnel with shell?
Best Answer
You need to forward port
3306
not port3305
.