简体   繁体   中英

Not able to connect AWS RDS (MYSQL) From EC2

Hi I am trying to host PHP code in AWS EC2(Windows) server on IIS. I am able to host the php webpages but the issue is the the webpages are not able to communicate to AWS RDS. PHP Code for Database:

<?php
$con=mysqli_connect("mysqldatabase.xxxxxxxxxx.ap-south-1.rds.amazonaws.com", "admin", "xxxxxxx", "detsdb", "3306");
if(mysqli_connect_errno()){
echo "Connection Fail".mysqli_connect_error();
}

  ?>

I am using default VPC rule and in both RDS and EC2 Security Group(Both Inbound and Outbound) I have opened all traffic as well as Opened SG id with port 3306 with each other.

**Error on Webpage: Connection FailServer sent charset unknown to the client. Please, report to the developers ** 错误图像

When I am trying the same code from my personal computer, I am able to communicate with RDS. I am using Wamp server to communicate and host it locally.

written a simple code to test the functionality that's also working:

<?php
$con = mysqli_connect("mysqldatabase.xxxxxx.ap-south-1.rds.amazonaws.com", "admin", "xxxxx", "detsdb", "3306");
if($con){
echo "Connection Success";
}
else
{
    echo "Error";
}

?>

成功连接

Please help me on this.

Ec2 SG 入口

EC2 SG 出站

RDS SG 入口

RDS SG 出站

Edit: Screenshot attcahed for both Ec2 and RDS SG

On the windows server make a.txt file, then rename the extension to.UDL open the file and use it as a quick way to test the connection.

Next follow this fix: PDO::__construct(): Server sent charset (255) unknown to the client. Please, report to the developers

If this fails create a second RDS DB in a private subnet and test John's advice about DNS resolving to private IP using the UDL file.

Go to the server and try to connect RDS directly and check whether you can able to access or not.

Basically Its a parameter group issue: so what i did was: Created a new Parameter group and then edited them. Searched all character-set parameters. These are blank by default. edit them individually and select utf8 from drop down list. character_set_results, character_set_server and SAVE. Now you can able to connect

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM