Not able to connect to Amazon RDS from EC2 Django Instance - mysql

I was deploying my Django Project on AWS (this is my first time doing this) after a lot of first time learning i got stuck at an error :
django.db.utils.OperationalError: (2005, "Unknown MySQL server host '****.*****.us-east-2.rds.amazonaws.com' (0)")
When i tried migrating my Django Project.I tried multiple solutions but none worked. I tried command mysql -u username -p password -h ****.********.us-east-2.rds.amazonaws.com but this also returned and error.
ERROR 2005 (HY000): Unknown MySQL server host '*****.*********.us-east-2.rds.amazonaws.com' (2)
UPDATE 2: I Tried using command on AWS Documentation mysql -h mysql–instance1.123456789012.us-east-1.rds.amazonaws.com -P 3306 -u mymasteruser -p which have -h before using -u and -p and an input for Port this changed the error which seems like now the connection is not not able to reach the server which seems a reasonable and a better error than before.
ERROR 2003 (HY000): Can't connect to MySQL server on '******.******l2la.us-east-2.rds.amazonaws.com' (10060)
I read in question this about this,they are talking about binding the instance to an IP.How can i do that if that could be the problem?
UPDATE1:
Screenshots:
FIRST RDS INFORMATION
EC2 instance Information
SGs information
If you require any log or information please feel free to ask in the comments.
Thanks

The security group of Database should hold a Value in Inbound Rules :
This Rule should allow connection from your EC2 Instance.Either set the IP Address or set the SG of EC2 Instance.
You can use the Private IP of your instance rather than the Public IP also.
(Not sure about Security Concerns or Advantages.)
Update After a Year: Well you should use private IP and not the same security
group.DB should only be accessible to the EC2 and not to public.

Related

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

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

Failing to connect to Sequel Pro with '127.0.0.1', but can connect via terminal with 'localhost'

I have a project running on Docker and I'm able to connect to the database through the terminal:
mysql -h localhost -P 33060 --protocol=tcp -u 'notmyrealusername' -p
This works fine and I'm able to show the tables from the database.
However, when trying to connect via SequelPro, I get the following error:
Unable to connect to host 127.0.0.1, or the request timed out.
Be sure that the address is correct and that you have the necessary privileges, or try increasing the connection timeout (currently 10 seconds).
MySQL said: Protocol mismatch; server version = 11, client version = 10
Note that the project is running on MySQL 5.7.34 and the version on my computer is 8.0.23.
OS: Mac OS Catalina
What I have tried:
From this thread, I have tried also with the port of 2200 and, well, SequelPro won't let me use 127.0.0.1. So, I couldn't try the second one.
I have also granted all privileges to both 'notmyrealusername'#'127.0.0.1' and 'notmyrealusername'#'localhost', but that didn't seem to fix it either.
Replying to Philippe's questions:
Yes, If I try mysql -h 127.0.0.1, then I get the same error:
ERROR 2007 (HY000): Protocol mismatch; server version = 11, client
version = 10
Question:
Does anyone know either how to connect to 'localhost' and not '127.0.0.1' on SequelPro or why I can't seem to connect to this database on SequelPro, when, with the same data, I can easily connect via terminal?
Thanks in advance for all of the help/suggestions you can provide!
Thanks!
I have finally found the solution. For anyone wondering, the key here is that I am using Docker. In this case, as outlined in this forum post, we need to:
Use the IP address of the machine where the database is running (the
real one, not localhost) as host address.
How?
Go to your terminal and use the command ifconfig . You'll get a bunch of data, but what you're looking for is the local network IP address. This usually looks like either 192.x.x.x or 10.x.x.x.
Then, in Sequel Pro or whatever GUI you are using, use this address (192....) instead of localhost.
I hope this helps someone and saves you time :)
Happy coding!

AWS RDS MySql - how to allow access after setting 'Publicly available'

Just created new AWS RDS MySql instance with default settings and user/pass.
Also I set it to be publicly available and to create a new VPC during the process.
Currently can not connect from my laptop to this RDS:
mysql -h endpoint -u myusername -p
error:
ERROR 2003 (HY000): Can't connect to MySQL server on 'endpoint' (60)
How to allow access to it from e.g. my laptop and other computers? If is trough some security groups - where exactly to change and associate with new RDS instance trough console?
Thanks.
On the instance page, just under the monitoring graphs there is a connect block with a list of security groups.
There should be 1 group of type security group - inbound
On that security group's page you should have an inbound tab at the bottom.
Click on Edit et add a new rule for your current IP. Make sure the port is correct.
Now you should be able to connect with mysql -h [ENDPOINT] -P [PORT] -u [USERNAME] -p
If you are behind a proxy this may still fail. You'll have to tunnel your way in or used a shared wifi connection.

Got error: 2003: Can't connect to MySQL server while taking dump from RDS

I am trying to export database from AWS RDS to my localhost, mysql dump command is like:
`mysqldump -h xxxxx(my RDS account) -u xxx(my username) -p remote_db > dump.sql`,
then my terminal would ask me to enter the password, after entering passsword, it kept showing Got error: 2003: Can't connect to MySQL server, what may cause this problem? I have checked this
Can't get mysqldump to connect to local mysql instance (error 2003 / 10061)
and try to use this solution to fix it, but same thing happens everytime, what can i do?
It is a best practice that your database should be always private so most probably your database would be in private subnet(Not accessible from internet), If RDS is accessible from the internet so check your Security Group, NACL & Route Table configuration.
Feel free to comment if you face same issue the after above checklist.

MySQL federated host "my ip" is not allowed to connect mysql server

I've confused about this problem, and still stuck out of it for a week.
I've trying to federated table in mysql, but when tried to do query select to remote table. I got this message
Error Code: 1429. Unable to connect to foreign data source: Host '172.25.97.136' is not allowed to connect to this MySQL server
while 172.25.97.136 is my ip static address not remote server's ip address
i've read this solution Host 'xxx.xx.xxx.xxx' is not allowed to connect to this MySQL server But still didn't work.
anyone can help, please?
Can you check, are you able to connect to that mentioned ip using mysql as,
mysql -hXX.XX.XX.XX -u -p
If you are unable to login with above command,clearly it is a permissions issue.
Please check.
Thanks,
Lakshmi