doulei8861 2017-08-13 18:28
浏览 119
已采纳

连接到在Ubuntu AWS实例中创建的MySQL数据库

Ok so I created an ubuntu instance from AWS and downloaded LAMP on it as you would in a regular Ubuntu OS. When I try to connect to the db from my php script it's rejecting the connection. saying "Connection failed: Connection refused". So I guess my question is this: Does amazon not allow you to connect to a db without using their RDS database service or am I putting something wrong here? (I've hidden some of the data for security purposes, the ... are numbers of my instance). When I put "ec2-34-...-..-64.compute-1.amazonaws.com" into the browser the apache message comes up so I don't see why this is not working as a server name?

$servername = "ec2-34-...-..-64.compute-1.amazonaws.com";

$username = "root";

$password = “hidden"; 

$dbname = "questions87";


// Create connection

$conn = mysqli_connect($servername, $username, $password, $dbname);

// Check connection

if (!$conn) {

  die("Connection failed: " . mysqli_connect_error());

}
  • 写回答

1条回答 默认 最新

  • doudoulb1234 2017-08-13 19:57
    关注

    You need to change your EC2 Security Group Inbound Rules related with 3306, you can find that on the AWS FAQ. Then, you need to be sure that your user@YOURIP have all permissions on your MySQL database. For your Inbound Rules it is recommended to use a Custom Rule to your IP, not All Traffic.

    Reference and further reading:

    http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/authorizing-access-to-an-instance.html

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么