AWS RDS和PDO无法运行SQLSTATE [HY000] [2002] [英] AWS RDS and PDO don't work SQLSTATE[HY000] [2002]

查看:101
本文介绍了AWS RDS和PDO无法运行SQLSTATE [HY000] [2002]的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用RDS创建了MySQL 5.7数据库.

I created my MySQL 5.7 database with RDS.

之前,我通过PDO连接到与Web服务器位于同一服务器上的数据库.不是EC2的服务器.一切都很好.

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.

我创建了RDS数据库并使用AWS ID修改了数据库的类,现在它不再起作用了.

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

连接信息似乎正确,因为我可以从MySQL Workbench连接到它.

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

这是我的代码:

$_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);

这是错误消息:

PDOException:SQLSTATE [HY000] [2002]连接尝试失败因为关联方在一段时间后未正确响应时间,或建立的连接失败,因为连接的主机具有无法回应.

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.

您认为这是怎么回事?

推荐答案

检查您的安全组:

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

我怀疑您正在向RDS侧发送数据库流量的端口未打开,无法传入或传出.或者,但是,我认为出站的端口对所有人开放.

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.

例如,如果使用默认端口3306,则需要确保同时为3306打开了RDS安全组和Web服务器安全组端口.

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.

来自显示为重复项的帖子:

1)登录到您的AWS控制台并转到"EC2"

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

2)在左侧菜单中的网络和网络"下.安全"进入安全组"

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

3)检查有问题的安全组

3) Check the Security Group in question

4)单击入站选项卡"

4) Click on 'Inbound tab'

5)从下拉列表中选择"MYSQL",然后单击添加规则"

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

如果您需要更多帮助,请随时告诉我.

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

这篇关于AWS RDS和PDO无法运行SQLSTATE [HY000] [2002]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆