AWS PHP PDO MySQL连接问题SQLSTATE [HY000] [2002]

I am trying to connect to my AWS MYSQL database following this tutorial: https://docs.aws.amazon.com/zh_cn/elasticbeanstalk/latest/dg/create_deploy_PHP.rds.html#php-rds-connect.

My Code

<?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);
?>

The output

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

I am able to connect to my database with MySQL Workbench.

Any help would be greatly appreciated!

Please verify your Database settings. May be it's a wrong port setting.If you use localhost you can try to change the host to 127.0.0.1. The MySQL process might be stuck.