简体   繁体   English

无法从 EC2 连接 AWS RDS (MYSQL)

[英]Not able to connect AWS RDS (MYSQL) From EC2

Hi I am trying to host PHP code in AWS EC2(Windows) server on IIS.嗨,我正在尝试在 IIS 上的 AWS EC2(Windows)服务器中托管 PHP 代码。 I am able to host the php webpages but the issue is the the webpages are not able to communicate to AWS RDS.我能够托管 php 网页,但问题是网页无法与 AWS RDS 通信。 PHP Code for Database: PHP 数据库代码:

<?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.我正在使用默认 VPC 规则,并且在 RDS 和 EC2 安全组(入站和出站)中,我已经打开了所有流量以及打开的 SG id 与端口 3306。

**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.当我在我的个人计算机上尝试相同的代码时,我能够与 RDS 进行通信。 I am using Wamp server to communicate and host it locally.我正在使用 Wamp 服务器在本地进行通信和托管。

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编辑:Ec2 和 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.在 windows 服务器上制作一个 .txt 文件,然后将扩展名重命名为 .UDL 打开该文件并使用它作为测试连接的快速方法。

Next follow this fix: PDO::__construct(): Server sent charset (255) unknown to the client.接下来遵循此修复: PDO::__construct():服务器发送的字符集 (255) 对客户端未知。 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.如果此操作失败,则在私有子网中创建第二个 RDS 数据库并测试 John 关于 DNS 使用 UDL 文件解析为私有 IP 的建议。

Go to the server and try to connect RDS directly and check whether you can able to access or not. Go 连接到服务器,尝试直接连接RDS,查看是否可以访问。

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.分别编辑它们并从下拉列表中编辑 select utf8。 character_set_results, character_set_server and SAVE. character_set_results、character_set_server 和 SAVE。 Now you can able to connect现在您可以连接了

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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