我能够连接远程PC的phymyadmin,但是当我尝试连接到远程数据库时,我收到连接拒绝错误。
我见过类似的问题,但现在还没有回答,现在还不活跃。SQLSTATE[HY000] [2002] Connection refused with right port
<?php
$servername = "192.168.1.12";
$username = "root";
$password = "root";
try {
$conn = new \PDO("mysql:host=$servername;dbname=my_db", $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();
}
?>
答案 0 :(得分:0)
在远程pc中,mysql配置文件中的绑定地址设置为127.0.0.1而不是192.168.1.12