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.
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)
Related
I'm having a bit of an issue with connecting to my Amamzon RDS (Mysql) instance through a fresh Lumen installation on an Amazon EC2 instance.
The Lumen installation uses the PDO class.
The problem:
I can't connect to my RDS, I'm simply getting a timeout when trying:
SQLSTATE[HY000] [2002] Connection timed out
What have i tried?
I've tried connecting directly to the ip of my rds instance. Same result.
When debugging my connection, I get a connection string like mysql:host=x.x.x.x;port=3306;dbname=(...) - ip and db are correct. Username and password are also correct when debugging the connection.
Connecting from another server, that is outside Amazon AWS. Also using PDO = negative result
Checking that the RDS is set up to available from the outside = It is, I can connect from my own computer. Tested with two different machines.
Looking through various posts about rds and timeouts = no usable solutions
Connected directly to the ip of my RDS instance = negative result
When developing on my local machine, I'm not having any problems connecting to the same rds.
Anything else you should know?
When connecting from my computers (using Sequel Pro), i can connect - I've tried from two computers, both with positive result. This is indifferent if i use the domain/endpoint of the rds instance or connect directly to the ip.
By my own logic, I should be ablet to connect from any EC2 instance, since I can connect from my own computer.
Any help would be appriciated.
Did you actually give the right permission inbound to RDS from that EC2 Instance?
You need to modify your security group to give access.
Hi I am trying to connect to my MySQL DB which is hosted by strato. On their site I can create a DB and I did. Now I am trying to connect to the database via NaviCat but I keep getting error 10060.
A screenshot of the strato website: screenshot strato webportal
A screenshot of my trying to connect to the database in NaviCat: screenshot NaviCat
And last but not least a screenshot of their website with an tutorial on how to connect to the DB: link to page
Maybe you're wondering why I don't contect the host, it takes ages for them to reply...
What am I doing wrong why cant I connect how can I fix it?
EDIT/UPDATE
I now setup a SSH tunnel but when I am trying to connect it still gives me this errorlost connection to mysql server at 'reading initial communication packet' system error 0
I am able to connect via PuTTy like shown in this link. And a found the port, hostname etc as you can see
But once I fill that into NaviCat, like this
and this
but still no luck :S now gettings this error:
If anyone can help me i would rlly appreciate it!
My guess is that Strato is blocking outside access to your database. Which is 100% good. Allowing internet access to a database is generally a bad idea.
You can connect to the database by SSH'ing to the server and then using mysql CLI. Instructions are provided in the link you shared in the SSH-access to the MySQL database section.
Using SSH you can also port tunnel to allow your remote connection with your client. This is a slightly more advanced technique where you link up a port on your local computer (localhost) to a port on the remote machine to which you are ssh'ing.
In PuTTy put in the server name like their instructions suggest:
Then go to SSH>>Tunnel in the left-hand menu. Fill out your Source Port (the port your local computer will be listening on) and your Destination (The server:port on the REMOTE computer that you are forwarding traffic to through the tunnel):
I'm using local port 66306, you may use whatever port you want as long as it isn't be used on your computer. Click "Add" and then Open the connection and put in your username/password when prompted. Refer to that Strato help doc if you get stuck.
NOW... in your mysql client (Navicat) you are going to connect your database. Because you have a tunnel open forwarding traffic from YOUR computer's 63306 port (or whatever port you chose) to the remote computers 3306 port you will specify in Navicat:
Connection Name: Whatever
Hostname/IpAddress: localhost
Port: 63306
Username: strato db username
Password: strato db password
Now it should connect. Strato sees your traffic as if it's coming from their server because of the tunnel and it will allow you through.
There is a server I wish to connect to. It has multiple VMs running on it each VM has a mysql DB. I can currently connect to this server using ssh and then connect to any of the databases from each VM using mysql -u user -h host -p password. Now I want to connect to the same MySQL DBs using MySQL workbench from my local machine. However there is firewall, currently I use putty to get passed the firewall with public private key authentication and I can access any machine I want. I have seen here that I must install a MySQL server locally ( I've done this I am using mysql workbench) and use the loop-back address, in that way you don't need to access an external server. Could anyone point in the right direction on how to do this?
You need to use ssh tunnelling.
In putty under the options go to Connection->SSH->Tunnels. Add a tunnel from source port 13306 to Destination localhost:3306.
You can do this in Putty either before or after you connect. It's best to do beforehand and save the session configuration otherwise it gets tedious having to re-enter the settings.
In MySQL workbench connect to localhost port 13306.
There is a good guide with screen shots here: Setting up an SSH tunnel with PuTTY
An SSH tunnel makes a TCP port on your SSH client machine and directs any traffic to whatever the destination is set to. You can add multiple tunnels, but each one must listen on a different source port number.
You can forward the port via SSH.
ssh -NL is your friend like so:
ssh -NL 3306:localhost:3306 <yourserver>
Then you can point your workbench at localhost.
You don't need any additional software for this task. MySQL Workbench can create SSH tunnels on its own. Watch my tutorial on Youtube how to create connections: https://www.youtube.com/watch?v=DCgRF4KOYIY.
It essentially comes down to creating the right connection type. There is a drop down that allows you to select an SSH connection. Enter the parameters which you used to connect via Putty.
I am using Amazon EC2 with Amazon RDS.
I have successfully created database and uploaded code to amazon using Elastic Beanstalk.
Now I want to import my local databse data to RDS databse. I surf and found that by mysql command we can do that so I do this
D:\wamp\bin\mysql\mysql5.5.8\bin>mysql --host=myinstances.aa23swersdf.us-east-1.rds.amazonaws.com --user=username --pass=password --port=3306 dbname < locahost.sql
But it throws this error :
ERROR 2003 (HY000): Can't connect to MySQL server on 'myinstances.aa23swersdf.us-east-1.rds.amazonaws.com' (10060)
How can I solve it?
I have do this by cmd on windows.
Hope this helps.
Make sure port 3306 is allowed on the Amazon EC2 Instance firewall.
Add security group that allows port 3306
On the mysql of both local and amazon, add the host myinstances.aa23swersdf.us-east-1.rds.amazonaws.com with your corresponding username and password.
Flush privileges.
You can also used MySQL Connector to test. It is available to download at the Internet.
Have you added your IP Address to the security group.
Or you can install phpMyAdmin on one of the AWS instances, assign it to the security group and then run the import.
I have an amazon EC2 instance (redhat linux ) and a RDS (mysql 5.5 ). After stop /start EC2 instance. EC2's ip was changed and cannt connect RDS anymore. I can successfully connect RDS instance from command line. However, it is unable to connect from php script and give me this warning.
PHP Warning: mysqli::mysqli(): (HY000/2003): Can't connect to MySQL server on 'applicantdb.xr3x2xcale.eu-west-1.rds' (13)
It is working fine from my localhost and I can connect to localhost. It is really annoying and if somebody knows the solution. Please help me and I do really appreciate it.
Thanks layke , the problem solved
The solution was
It restricts Apache remote database connection as default. So our scripts work in command line (# php sqltest.php), and mysql can connect to server but when Apache is involved (calling a php script as web page) then it doesn't work.
Setting:
setsebool -P httpd_can_network_connect=1
You need to in your RDS Security group make sure that your Amazon EC2 security profile has access.