2

I am very new to Amazon Web Services, I have created Mysql DB on RDS and stored some data.

Now i want to connect to RDS db from localhost(which is in running on my desktop) ,Tried as fallow in my PHP connection.

$con = mysql_connect("XXXX.XXXXX.XX-XX-X.rds.amazonaws.com:3306", "XXX", "XXX");

But getting error as fallows

Could not connect: Can't connect to MySQL server on 'awsniti.XXXX.rds.amazonaws.com'

Also tried giving my local IP address to Inbounds of Security Group. But couldn't connect.

googled a lot, but not able to find right answer.

Please help me with this issue.

Nikolay Kostov
  • 16,433
  • 23
  • 85
  • 123
Kiran
  • 61
  • 1
  • 7

1 Answers1

0

Adding the internet IP of your local network/machine on the security group associated with your RDS database should work. But I prefer to create a SSH tunnel through a server that I already gave access to the database. This way you don't have to care about the security group configuration every time you need to connect from a different IP address.

If you are on Linux or OSX you can run locally ssh -f user@your-web-server.com -L 3306:XXXX.XXXXX.XX-XX-X.rds.amazonaws.com:3306 -N and then connect localhost:3306 from PHP to access the RDS database. If you are on Windows it's also possible to create a tunnel using Putty (http://bit.ly/1GQmaYo)

Uilton Dutra
  • 394
  • 1
  • 4
  • Hi.. After i create a SSH tunnel , Can i able to connect to RDS DB through PHP Connect ? – Kiran Jul 06 '15 at 05:26
  • Yes you can connect locally to the remote RDS database. After you establish the tunnel you can connect as if it was running in your local machine `$con = mysql_connect("localhost:3306", "XXX", "XXX");` – Uilton Dutra Jul 06 '15 at 18:50
  • Thank you so much for your help. Now i got one more requirement , Here i want to access local database from PHP file which is in EC2 server.. Is there anyway ? – Kiran Jul 29 '15 at 11:05