aws php pdo mysql连接问题sqlstate[hy000][2002]

vnzz0bqm  于 2021-06-20  发布在  Mysql
关注(0)|答案(1)|浏览(478)

我正在尝试按照本教程连接到我的aws mysql数据库:https://docs.aws.amazon.com/zh_cn/elasticbeanstalk/latest/dg/create_deploy_php.rds.html#php-rds连接。
我的代码

<?php
$dbhost = $_SERVER['RDS_HOSTNAME'];
$dbport = $_SERVER['RDS_PORT'];
$dbname = $_SERVER['RDS_DB_NAME'];
$charset = 'utf8' ;

$dsn = "mysql:host={$dbhost};port={$dbport};dbname={$dbname};charset={$charset}";
$username = $_SERVER['RDS_USERNAME'];
$password = $_SERVER['RDS_PASSWORD'];

$pdo = new PDO($dsn, $username, $password);
?>

输出

SQLSTATE[HY000] [2002] No connection could be made because the target machine actively refused it.

我可以用mysql工作台连接到我的数据库。
任何帮助都将不胜感激!

gjmwrych

gjmwrych1#

请验证您的数据库设置。可能是端口设置错误。如果使用localhost,可以尝试将主机更改为127.0.0.1。mysql进程可能会被卡住。

相关问题