Unable to connect to AWS RDS using AWS CLI - Error 2002 - mysql

I've set up a basic AWS RDS in the free tier. No public access but created a security group with my IP address added as an inbound rule.
For authentication I have RDS password plus AWS IAM.
I try to connect to the db via my computer (Ubuntu) with the following command:
mysql -h <db-conn>.amazonaws.com -P 3306 -u admin -p
I've already looked at this answer - Cant connect to mysql server on AWS RDS My port isn't blocked and I've checked the security group. I am able to successfully run AWS CLI commands like this:
aws rds describe-db-instances --filters "Name=engine,Values=mysql" --query "*[].[DBInstanceIdentifier,Endpoint.Address,Endpoint.Port,MasterUsername]"
But every time I run the mysql command, I get the following error:
ERROR 2002 (HY000): Can't connect to MySQL server on '<db-conn>.amazonaws.com' (115)
Would love some assistance with this. Thanks!

For being able to connect to your AWS RDS system and not letting anyone to connect you need to do the following steps:
Set your Publicly Accesible property to YES in your RDS configuration. That will give the system a Public Subnet address and allow it to be accesible from outside your VPC.
Go to your security group and allow access to your RDS system (the port 3306 that you are trying to connect) only from your VPC and from your public IP. This makes changes in your firewall rules.
In that way you will be able to access your RDS from your public IP, but noone else will be able to access.

check your ip that config in the security group, it is need your public ip not like '192.168.xxx.xxx', you can get your public ip by google

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

Why can't I connect to my AWS RDS instance?

I am trying to connect with the username, password I've set up with the given host name. I can't connect. I've checked the security group to be configured correctly at PORT allowing incoming from "My IP" which populated my IP there.
What else could I be doing wrong?
When I try to get into the DB using the following command in my terminal:
mysql -h [aws-hostname-endpoint] -P 3306 -u admin -p
I get:
ERROR 2003 (HY000): Can't connect to MySQL server on [aws-hostname-endpoint] (60)
When you setup your RDS instance, also be sure to allow for public access if you want to connect to it from your development machine. SO two things to check:
allow public access for the RDS instance
make sure you inbound rules are setup to allow for a connection from your IP address.
Once you do these two tasks, you will be able to connect via a tool such as MySQL Workbench.
These RDS endpoints are not public (and they shouldn't be), so you can't use them on your computer to connect to them. You could make these endpoints public, but that's not a good idea/design. It's better if you try to connect inside an AWS environment (i.e EC2). Then you can restrict access to that using SSH keys.
We usually create a Bastion server for this purpose to act as a proxy, then you can use an SSH tunnel to connect to the RDS instance. Then all your traffic will be routed through the Bastion server in a secured tunnel.

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.