Connecting to an RDS from an EC2 on different subnets without NAT - mysql

I have an RDS instance running on one subnet without NAT, and an EC2 instance running on another subnet with an Internet Gateway configured, both located in the same VPC. I have configured the RDS instance to not be publicly accessible.
I am using the following command in my remote EC2 (running on the second subnet) to connect to the RDS instance:
mysql -h xxxx.eu-central-1.rds.amazonaws.com -P 3306 -u root -p
I have entered the correct password which I have set when configuring the RDS, but I get the following error:
Can't connect to MySQL server on xxxx.eu-central-1.rds.amazonaws.com
What am I doing wrong? Am I missing something?

You most likely need to open port 3306 in the security group assigned to the RDS server. In particular, create a rule allowing ingress on port 3306, and for the source use the ID of the security group assigned to the EC2 server.

The Security Group ingress rules for your subnet and/or your PostgreSQL instance must have port 3306 open for PostgreSQL. If you have changed the default port, you must use that port instead.
Your EC2 instance should not have to communicate through the internet to reach it, it just needs the proper port open in the security groups.
If you are not allowing all egress data in your EC2 security group, then you will need to ensure egress port 3306 is open on the EC2 security group, to the RDS security group.

Related

Can't connect to AWS RDS MySQL server, ERROR 2003 (HY000)

I have an AWS RDS database I can't connect, I get the following error:
mysql -h rds.eu-west-1.rds.amazonaws.com -P 3306 -u admin
ERROR 2003 (HY000): Can't connect to MySQL server on 'rds.cfckm0d26fsq.eu-west-1.rds.amazonaws.com:3306' (60)
The RDS security group allows all traffic for my IP as well explicit opens 3306
Also I have my RDS as Publicly accessible (which I don't like)
To travelshoot, I also open my security group to the world: 0.0.0.0/0, but the error remains
You needn't keep the security permissions Public.
You can just add the public IP of the inbound traffic to the Security Group for the RDS DB you are using. When you open the RDS DB instance, open the VPC Security Group --> Security Group ID --> Edit Inbound Rules --> Add your IP .
This solved my issue.
As I was on a private subnet, t didn't matter if I opened ports to the world. To trouble shoot I telnet the RDS
telnet rds.eu-west-1.rds.amazonaws.com 3306
And I saw there was no connectivity. So I created an EC2 within the same subnet and from it connected to the RDS.
NOTE: no need to have all traffic open (as I saw on my posts and youtube), just 3306 to private or requesting ip and for port 3306. Also no need to make the RDS public

Unable to connect AWS RDS MySQL from public IP of EC2 isntance

From my EC2 instance, I am able to connect to MySQL AWS RDS instance with mysql command as shown below if the RDS security group allows traffic from anywhere on port 3306. However, if I set the VPC default security group (also attached to the RDS instance) to accept 3306 traffic only from the public IP address of this EC2 instance, then the connection does not go through.
export MYSQ_PWD=password
mysql -h AWS_RDS_HOST -P 3306 -u admin
The EC2 and RDS instances are part of testing some functionalities of our application and required to be fully automated and 'throwaway' in nature. However, I don't want to keep the access as wide as 0.0.0.0/0 but limit to the IP address of the EC2 instance. The IP address of the EC2 instance is derived from curl -s http://checkip.amazonaws.com/.

Can't Connect to RDS mysql DB from Wordpress on Amazon linux EC2 Instance

I am getting Error establishing a database connection while trying to connect to mysql on Amazon RDS from my Wordpress instance.
Wordpress is on my AWS Linux EC2 Instance, both are on the same VPC, same Security Group allowing 3306 inbound rule, db credentials in wp-config is also correct.
I am able to connect to my mysql RDS instance while ssh with the following command and it connects fine:
mysql -h "endpoint url" -u "username" -p "password";
However, when accessing the EC2 EIP on the browser to setup my WP final configuration I get the error connecting DB.
Did you check your security group? Because you have to open the MySQL Port 3306.
When you are creating the RDS, it is important to create a new security group, like myRDSgroup, later you have to modify it by open the port 3306 in the source select the security group where your AWS EC2 is located.
Could you send your security group screenshot, please?

access RDS through ec2 beanstalk instance

I have an RDS instance running and I want to access it from a beanstalk instance. They are both in the same VPC and I have followed the instructions from the amazon documentation link.
Here is my table for the inbound rules I have assigned to the security group of the RDS instance.
The sg-c6...etc is the security group of the beanstalk instance.
When I am trying to run
mysql -u master -ppass -h rds.instanceid.eu-central-1.rds.amazonaws.com dbname
I am getting
ERROR 2003 (HY000): Can't connect to MySQL server on 'rds.instance.eu-central-1.rds.amazonaws.com' (110)
It seems to me like you have an issue with networking restrictions within your VPC.
Please try to login to your AWS account and navigate to the VPC management section. Navigate to Route Table and select your route table. Edit your Subnet Associations and make sure that all subnets are included
By default, MySQL server will run on port 3306 but your security group says 3310. MySQL on RDS will be no different. I would suggest changing the security group port to 3306.

Unable to connect to MySQL AWS RDS instance from local MySQL

I have created an MySQL RDS instance with VPC. Now i am trying to connect to that RDS instance from my Ubuntu 12.04 machine using MySQL client by following code:
mysql -u uname -h test.c6tjb4nxvlri.us-west-2.rds.amazonaws.com -P 3306 -p
But i am getting this error:
ERROR 2003 (HY000): Can't connect to MySQL server on 'test.c6tjb4nxvlri.us-west-2.rds.amazonaws.com' (110)
I searched about this error and everywhere solution came out like
Go to the Instances
Find the security group
Change the inbound rules of that security group by
Adding source of user machine public ip or
Set source ip as 0.0.0.0/16
I tried everything but still same error occures. Any explanations?
The problem was in subnet. Subnet that you created must be publicly accessible.
In On-premises MySQL Workbench, use TCP/IP SSH Tunneling option. Make sure you have EC2 instance endpoint and keypair file.
In SSH endpoint - add your EC2 instance endpoint and for SSH password, browse your keypair. Rest of configurations for MySQL. Like MySQL's endpoint, username, password, port and schema name.
Test your connection it will return success. If not, check RDS Security group. In Security group, you open MySQL port for all IP address. Try it! it will work. Once connection was success, all schema are visible in MySQL Workbench.
RDS DB instance need not to be in public subnet and it is not best practice to do. Always keep RDS DB instance in private subnet and open traffic for EC2 instance.
When you use TCP/IP SSH Tunneling, request traffic will send through EC2 instance to RDS DB instance.
HTH.