php – Unknown MySQL server host

php – Unknown MySQL server host

This is usually the case when name resolving doesnt work on the host. If your connect destination is always the same, you might want to use its IP address for connecting instead.

If you use this code:

$Mysqli= new mysqli(mysql2.servidoreswindows.net:3306,
                    usu, pass, dbname);

you can try to write host without port

That is:

$Mysqli= new mysqli(mysql2.servidoreswindows.net, usu, pass, dbname);

php – Unknown MySQL server host

Please pay attention with AWS security groups:

In my case I can connect to RDS from my computer throw Telnet and
I can connect throw Mysql Workbench also but I cant connect from
my EC2 instance that is within the same VPC as the RDS.

The solution was:
1. I have created a security group (exampl1) for RDS and assigned to it.
2. I have created a security group (exampl2) for EC2 and assigned to it.
and I have assigned the RDS security group (exampl1) to the EC2 too. << this saves me.

Info: If your EC2 has assigned 2 or more security groups, then in the RDS security group inbound source has to create rules as many security groups has your EC2 assigned.

Amazon docs says:
The EC2 instance in the VPC shares the same VPC security group with the DB instance.
http://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/Overview.RDSSecurityGroups.html

I spent all day searching docs.
I hope this help you.

Leave a Reply

Your email address will not be published.