0

I created my MySQL 5.7 database with RDS.

Before, I connected with PDO to a database on the same server as the web server. Server that is not an EC2. All worked well.

I create my RDS database and modify my class for the DB with the AWS id and now, it doesn't work any more.

The connection information seems correct because I can connect to it from MySQL Workbench.

Here is my code:

$_HOST = 'xxxxxxxxx.us-east-2.rds.amazonaws.com';
$_PORT = 3306;
$_DBNAME = 'xxxxx';
$_USER = 'xxxx';
$_PASS = 'xxxx';

$connexionString = "mysql:host={$_HOST};port={$_PORT};dbname={$_DBNAME}";

self::$_instance = new PDO($connexionString, $_USER, $_PASS);

And here is the error message:

PDOException: SQLSTATE[HY000] [2002] A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.

What do you think is going on?

halfer
  • 19,824
  • 17
  • 99
  • 186
Enzo B.
  • 2,341
  • 1
  • 11
  • 33
  • try remove braces, and port. –  May 02 '19 at 14:16
  • 1
    Check if your AWS config has a whitelist you local public ip address on your server... –  May 02 '19 at 14:19
  • Check this: https://mariolurig.com/coding/connect-remotely-mysql-database-amazon-ec2-server/ –  May 02 '19 at 14:22

1 Answers1

1

Check your security groups:

https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/Overview.RDSSecurityGroups.html https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/USER_WorkingWithSecurityGroups.html

I suspect the port you are sending DB traffic to on the RDS side isn't open for incoming or outgoing. Or, the port isn't open for incoming or outgoing on your web server, though, I imagine the outgoing ones are open to all.

For example, if using the default port of 3306, then you need to make sure both the RDS security groups and your web server security group ports are open for 3306.

Taken from the post shown as the duplicate:

1) Log into you AWS Console and go to 'EC2'

2) On the left hand menu under 'Network & Security' go to 'Security Groups'

3) Check the Security Group in question

4) Click on 'Inbound tab'

5) Choose 'MYSQL' from drop down list and click 'Add Rule'

If you need any more help feel free to let me know.

Adam
  • 1,294
  • 11
  • 24
  • 1
    Thanks for your help, I had to add the ip of my server in the EC2 security group for RDS and it works. – Enzo B. May 02 '19 at 14:35