简体   繁体   English

AWS EC2 RDS无法连接到mysql

[英]AWS EC2 RDS cannot connect to mysql

I have a MySQL server running in RDS. 我有一个在RDS中运行的MySQL服务器。 I am able to connect to it when I'm running my website on localhost. 当我在localhost上运行我的网站时,我可以连接到它。 But when I try to connect to myself through my website being hosted by the EC2 instance I can't connect. 但是,当我尝试通过由EC2实例托管的网站连接到我自己时,我无法连接。 I tried looking through the security groups in the EC2 and it has as in inbound rule the following: 我尝试查看EC2中的安全组,它具有以下入站规则:

MYSQL/Aurora. MYSQL /极光。 TCP. TCP。 3306. 0.0.0.0/0 3306. 0.0.0.0/0

I'm sure the password, username, host, and database are correct because I can connect with them on localhost and through MySQL workbench. 我确定密码,用户名,主机和数据库是正确的,因为我可以在localhost上通过MySQL工作台与它们连接。

I try to connect to mysql as follows: 我尝试如下连接到mysql:

$mysqli= mysqli_connect("blah.foo.us-west-2.rds.amazonaws.com:3306",'root','password', "innodb")or die($mysqli->error);

You should connect it like 你应该像这样连接

mysqli_connect("blah.foo.us-west-2.rds.amazonaws.com",'root','password',
"innodb",'3306')or die($mysqli->error);

Connection string look like mysqli_connect 连接字符串看起来像mysqli_connect

mysqli_connect(host,username,password,dbname,port,socket);

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

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