简体   繁体   English

尝试将EC2服务器连接到RDS mySQL时出错

[英]error trying to connect EC2 server to RDS mySQL

when i call a PHP file (it just echos some text) in my /var/www/html directory in my Ubuntu server it works. 当我在Ubuntu服务器上的/var/www/html目录中调用一个PHP文件(它仅回显一些文本)时,它就可以工作。 When i try to run this PHP script in my browser (try to connect to my EC2 database): 当我尝试在浏览器中运行此PHP脚本时(尝试连接到我的EC2数据库):

<?php

$con = mysql_connect("phpmyadmin.cvw71h2krjrb.us-east-1.rds.amazonaws.com:3306",root,"phpmyadmin") or die(mysql_error());
echo "Database connected.";

?>

i get this error: 我收到此错误:

Access denied for user 'root'@'172.31.56.54' (using password: YES) 用户'root'@'172.31.56.54'的访问被拒绝(使用密码:是)

My security group is wide open and i know everything works because i can sign into phpMyAdmin and see my databases and i can echo PHP files. 我的安全组非常开放,我知道所有工作都正常,因为我可以登录phpMyAdmin并查看数据库,并且可以回显PHP文件。

how do i properly connect to a RDS database from a EC2 Ubuntu server via PHP? 我如何通过PHP从EC2 Ubuntu服务器正确连接到RDS数据库? or is there something wrong with my code? 还是我的代码有问题? Thanks! 谢谢!

It should be like this, remove :3306 from phpmyadmin.cvw71h2krjrb.us-east-1.rds.amazonaws.com:3306 and username should be surronded by double quotation( "root" ): 应该是这样,从phpmyadmin.cvw71h2krjrb.us-east-1.rds.amazonaws.com:3306删除:3306username应加双引号( "root" ):

<?php
$con = mysql_connect("phpmyadmin.cvw71h2krjrb.us-east-1.rds.amazonaws.com","root","phpmyadmin") or die(mysql_error());
echo "Database connected.";
?>

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

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