Remote database connection error with Amazon RDS | Unable to connect (10060) - mysql

I am facing difficulty in establishing remote database connection (MySQL / MariaDB) to AWS-RDS. On the server side (AWS RDS) everything looks fine and even Inbound rules are set to accept My IP ( TCP Protocol over Port 3306). I am working on Windows machine so the error might be related to Windows Firewall. For this reason, I even added new Outbound and Inbound rule in Firewall Manager and set Remote Port to 3306. But still I end with below connection error:
The following error occurred:
Can't connect to MySQL server on 'xxx.rds.amazonaws.com' (10060) QMYSQL: Unable to connect
Windows Firewall setting (similar for both Outbound & Inbound):
Amazon RDS is publicly accessible but still I am getting 10060 error. Is there something missing in Amazon (like in VPC) or is this caused by windows firewall?
I came across similar posts but those solutions didn't help. AWS RDS connection error
Can anyone please let me know what could be the issue and how to resolve it?
Update
After setting up VPC Flow logs to monitor the traffic, log messages are stored in S3 bucket with interval of 10mins. From 2 different logs, I could find:
version account-id interface-id srcaddr dstaddr srcport dstport protocol packets bytes start end action log-status
2 xx164 eni-08f88xxxx xx.xx.xxx.119 xxx.xx.2.17 34010 3306 6 5 260 1661944383 1661944424 REJECT OK
2 xx164 eni-08f88xxxx xx.xx.xxx.119 xx.xx.2.17 33953 3306 6 5 260 1661938359 1661938418 REJECT OK
The srcaddr, dstaddr and dstport is same in both cases but, srcport is different. Is this expected behavior? The srcaddr doesn't match with the IP addr set in security group (inbound rule). I don't understand which IP addr is taken as srcaddr.
Whereas doing telnet rdsendpoint 3306 results in Connecting To <rdsendpoint>...Could not open connection to the host, on port 3306: Connect failed
Thanks in advance.
P.S: please let me know if any info is missing here.

Related

"Cannot Connect to Database Server" error connecting from MySQL Workbench to SiteGround MySQL Database

Situation:
I am trying to connect to my SiteGround server MySQL database directly from my local machine using MySQL Workbench. I am positive that the connection properties are entered correctly as the connection works if I am connected to Network A (phone data plan). But with Network B, the connection failed.
I allowed remote access to my server from my Network B IP, in fact, I allowed all IPs just for testing, therefore Network A is working.
I checked if there is any setting that blocks the port from my router and modem in Network B, but I found nothing.
I tried running netstat: nothing with port 3306.
I tried running telnet: "connect failed"
Question:
I am suspecting that my ISP has blocked the outgoing port 3306? Is there anything I can do to "unblock" it?
Or is there any workaround for connecting to my server database?
My connection set up screenshot:
Error screenshot:
Thank you in advance for your time and help!!

Can't connect to mysql aws RDS - 10060 odbc logged error

I'm trying to debug an ODBC connection failing to a MySQL instance on aws rds. The connection works on all but a single machine. This machine is connected to large financial systems network, so I assume it would be the firewall.
So far, I've..
made rds instance public accessable
whitelisted the machine's IP
had their network folks open port 3306 on machine.
network folks confirmed data is going out port 3306, but nothing is coming back.
traced on machine's odbc log...10060 error (usually inbound rule to RDS error..)
opened ALL inbound to RDS to accept from all (0.0.0.0/0 ) - still get error
setup the RDS instance error log, but doesn't record these failed connects. It seems to only log if it is a user/password fail..?
my questions:
is there an aws rds log that would show these failed attempts?
does windows firewall on port 3306 also need an inbound rule? Or does opening it assume inbound/outbound?
Again - all the other machines are able to access the rds mysql fine. Only this one can not connect - and i am sure it's very protected, due to its access to major financial systems.
any ideas what else I can try?
thanks!
On your security group you will need to enable for public access (or just your IP), and sometimes it can take a long time to apply these changes, for me it took 5 hours once upon ago;
So I believe the issue is that on firewall setup, they are allowing incoming on 3306 only if its a secured connection (using ipSec I believe).
i'll likely need to look into a vpn to connect to AWS rds.

AWS: Not able to connect to mysql(rds) from wordpress

I'm trying to connect to mysql instance on rds via worpress, but I get this error:
Warning: mysql_connect(): Unknown MySQL server host '***********************' (111) in /var/www/html/wp-includes/wp-db.php on line 1568
Error establishing a database connection...
As I have read, (111) is for permission error. But I'm able to connect to the instance via workbench. In fact I was able to connect via wordpress earlier too.
This is driving me crazy. Please help. (My wp-config.php is correct. Checked it a 1000 times)
The following checks have to be done:
The subnet group for RDS needs to have inbound traffic enabled from the subnet group that has the WordPress server installed.
Make sure all NACL rules that control traffic between the subnets are not blocking this traffic
The WP server subnet group should not be blocking outgoing traffic to the RDS group. If needed add the RDS subnet group to the outgoing traffic from the EC2 instance hosting the WP server.

unable to connect to AWS VPC RDS instance (mysql or postgres)

(I'm posting this question after the fact because of the time it took to find the root cause and solution. There's also a good chance other people will run into the same problem)
I have an RDS instance (in a VPC) that I'm trying to connect to from an application running on a classic EC2 instance, connected via ClassicLink. Security groups and DNS aren't an issue.
I am able to establish socket connections to the RDS instance, but cannot connect with CLI tools (psql, mysql, etc.) or DB GUI tools like toad or mysql workbench.
Direct socket connections with telnet or nc result in TCP connections in the "ESTABLISHED" state (output from netstat).
Connections from DB CLI, GUI tools, or applications result in timeouts and TCP connections that are stuck in the "SYN" state.
UPDATE: The root cause in my case was a problem with MTU size and EC2 ClassicLink. I've posted some general troubleshooting information below in an answer in case other people run into similar RDS connectivity issues.
Additional information for people who might run into similar issues trying to connect to RDS or RedShift:
1) Check security groups
Verify the security group for the RDS instance allows access from the security group your source server belongs to (or its IP added directly if external to AWS). The security group you should be looking at is the one specified in the RDS instance attributes from the RDS console UI (named "security group").
NOTE: Database security groups might be different from AWS EC2 security groups. If your RDS instance is in classic/public EC2, you should check in the "database security group" section of the RDS UI. For VPC users, the security group will be a normal VPC security group (the name sg-xxx will be listed in the RDS instance's attributes).
2) Confirm DNS isn't an issue.
Amazon uses split DNS, so a DNS lookup external to AWS will return the public IP while a lookup internal to AWS will return a private IP. If you suspect it is a DNS issue, have you confirmed different IPs are returned from different availability zones? If different AZs get different IPs, you will need to contact AWS support.
3) Confirm network connectivity by establishing a socket connection.
Tools like tracepath and traceroute likely won't help since RDS currently drops ICMP traffic.
Test port connectivity by trying to establish a socket connection to the RDS instance on port 3306 (mysql, or 5432 for postgres). Start by finding the IP of the RDS instance and using either telnet or nc (be sure to use the internal/private IP if connecting from within AWS):
telnet x.x.x.x 3306
nc -vz x.x.x.x 3306
a) If your connection attempt isn't successful and immediately fails, the port is likely blocked or the remote host isn't running a service on that port. you may need to engage AWS support to troubleshoot further. If connecting from outside of AWS, try to connect from another instance inside AWS first (as your firewall might be blocking those connections).
b) If your connection isn't successful and you get a timeout, packets are probably being dropped/ignored by a firewall or packets are returning on a different network path. You can confirm this by running netstat -an | grep SYN (from a different ssh session while waiting for the telnet/nc command to timeout).
Connections in the SYN state mean that you've sent a connection request, but haven't received anything back (SYN_ACK or reject/block). Usually this means a firewall or security group is ignoring or dropping packets.
It can also be a problem with NAT routing or multiple paths from multiple interfaces. Check to make sure you're not using iptables or a NAT gateway between your host and the RDS instance. If you're in a VPC, also make sure you allow egress/outbound traffic from the source host.
c) If your socket connection test was successful, but you can't connect with a mysql client (CLI, workbench, app, etc.), take a look at the output of netstat to see what state the connection is in (replace x.x.x.x with the actual IP address of the RDS instance):
netstat -an | grep x.x.x.x
If you were getting a connection established when using telnet or NC, but you see the 'SYN' state when using a mysql client, you might be running into an MTU issue.
RDS, at the time this is written, may not support ICMP packets used for PMTUD (https://en.wikipedia.org/wiki/Path_MTU_Discovery#Problems_with_PMTUD). This can be a problem if you're trying to access RDS or RedShift that's in a VPC from a classic ec2 instance via ClassicLink. Try lowering the MTU with the following, then testing again:
sudo ip link show
# take note of the current MTU (likely 1500 or 9001)
sudo ip link set dev eth0 mtu 1400
If the lower MTU worked, be sure to follow up with AWS customer support for help and mention that you are seeing an MTU issue while trying to connect to your RDS instance. This can happen if TCP packets are wrapped with encapsulation for tunneling, resulting in a lower usable MTU for packet data / payload. Lowering the MTU on the source server allows the wrapped packets to still fit under the MTU limit while passing through the tunneling gateway.
If it didn't work, set your MTU back to it's default and engage AWS support for further troubleshooting.

Can't ping AWS RDS endpoint

I want to migrate my local mysql database to Amazon RDS. But first I want to test to see if it is receiving communication. So I try to ping it. But the attempt timeout.
ping -c 5 myfishdb.blackOut.us-west-2.rds.amazonaws.com
PING ec2-54-xxx-xxx-118.us-west-2.compute.amazonaws.com (54.xxx.xxx.118): 56 data bytes
Request timeout for icmp_seq 0
Request timeout for icmp_seq 1
Request timeout for icmp_seq 2
Request timeout for icmp_seq 3
I suspect that I need to open the inbound settings, so I open up the settings to
SSH TCP 22 72.xxx.xxx.xxx/32
And it still does not work. What do you suppose I am doing wrong? Am I missing anything else?
So I try to ping it. But the attempt timeout.
Ping won't work because the security group blocks all communication by default. You'll have to "poke holes" in the security group firewall to get traffic to your instance.
SSH TCP 22 72.xxx.xxx.xxx/32 And it still does not work.
Yup. RDS does not allow you to log in to the box via SSH. Only the MySQL port (3306) is open.
I want to migrate my local mysql database to Amazon RDS.
Ok, but be careful. DO NOT open up 3306 to the entire Internet (i.e. 0.0.0.0). MySQL was not designed for that, and often has flaws where anyone can break into your database.
You can open 3306 to just your (home) IP address (or the server you'll be using it from.) It should look like "5.5.5.5/32 TCP port 3306". But beware that this isn't great security because other people could see your packets. (MySQL supports encrypted connections, but you have to set them up explicitly.)
The best way to test a port is open is to telnet to the port. You can test your setup with telnet my.mysql.ip.address 3306. If you get no message, the port is not open. If you get "connected to ..", then your MySQL port is working.
The most secure way to use RDS is from an EC2 instance. You can create trust between the EC2 instance and the RDS security group. Your packets won't travel over the Internet, but only on the AWS network. Other people won't be able to see your packets, because nothing in EC2 allows that.
Amazon RDS is a managed service for relational databases. It does not give access to the low level infrastructure.
http://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/Welcome.html
There is no SSH, Telnet or Ping access authorised to an RDS instance
Seb
"RDS Instances are not configured to accept and respond to an ICMP packet for pings. The only way you can establish connectivity to your RDS instance is through a standard SQL client application."
This means, that adding ICMP rule into particular RDS security group, doesn't make your RDS instance reachable over ICMP.
The solution that worked for me is open the IP:PORT in security group section
Ping is blocked as others have said. To allow Amazon RDS to connect from your EC2 instance. Go to Security groups of your RDS instance. Edit "Inbound" settings. And Change "Custom" to "Anywhere". After that you will be able to connect to db.
You can use host from Linux, which is also what AWS says.
host <db_instance_endpoint>
This worked for me even when ping timed out.
AWS security groups block ICMP - which includes pings - by default. You'd have to open up ICMP - blindly trying to open TCP/22 isn't going to do anything.