连接在连接到远程服务器时拒绝

时间:2017-10-22 07:02:53

标签: php mysql digital-ocean

我是网络开发的新手。我在DigitalOcean上买了一台服务器,创建了一个Droplet并安装了LAMP。我有一个简单的PHP脚本连接到MySQL。这是我的PHP脚本(conn.php)

<?php
$servername = "xxx.xx.xx.xxx";
$username = "root";
$password = "my_password";
try {
    $conn = new PDO("mysql:host=$servername;dbname=mysql", $username, $password);
    // set the PDO error mode to exception
    $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
    echo "Connected successfully"; 
}catch(PDOException $e) {
    echo "Connection failed: " . $e->getMessage();
}
?>

现在,当我尝试在我的本地“xxx.xx.xx.xxx/conn.php”上运行时,它正在打印

Connection failed: SQLSTATE[HY000] [2002] Connection refused

0 个答案:

没有答案