连接失败:连接被拒绝 mysql (LAMP)
Connection failed: Connection refused mysql (LAMP)
当我尝试连接到 mysql 时,它拒绝了我的脚本。我在 ubuntu 16.10 (LAMP) 上安装了 mysql。
当我运行这个:
<?php
$servername = "ip";
$username = "user";
$password = "pw";
// Create connection
$conn = new mysqli($servername, $username, $password);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
echo "Connected successfully";
?>
显示:
Connection failed: Connection refused mysql (LAMP)
我尝试将绑定地址更改为 0.0.0.0,然后它显示:
Connection failed: Host 'webserver1' is not allowed to connect to this MySQL server
我试图评论 (#) 绑定地址。那也没用。
我 运行 将客户端上的脚本与另一个 ip-range/subnet 然后 mysql 服务器连接。当我在客户端上 运行 phpmyadmin 时我没有问题。
可能有安全防范措施。您可以尝试在 mysql.
中添加一个新的管理员帐户
mysql> CREATE USER 'yourUser'@'localhost' IDENTIFIED BY 'some_pass';
mysql> GRANT ALL PRIVILEGES ON *.* TO 'yourUser'@'localhost'
-> WITH GRANT OPTION;
mysql> CREATE USER 'yourUser'@'%' IDENTIFIED BY 'some_pass';
mysql> GRANT ALL PRIVILEGES ON *.* TO 'yourUser'@'%'
-> WITH GRANT OPTION;
尝试在您的代码中新建用户。
希望对您有所帮助!
当我尝试连接到 mysql 时,它拒绝了我的脚本。我在 ubuntu 16.10 (LAMP) 上安装了 mysql。
当我运行这个:
<?php
$servername = "ip";
$username = "user";
$password = "pw";
// Create connection
$conn = new mysqli($servername, $username, $password);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
echo "Connected successfully";
?>
显示:
Connection failed: Connection refused mysql (LAMP)
我尝试将绑定地址更改为 0.0.0.0,然后它显示:
Connection failed: Host 'webserver1' is not allowed to connect to this MySQL server
我试图评论 (#) 绑定地址。那也没用。
我 运行 将客户端上的脚本与另一个 ip-range/subnet 然后 mysql 服务器连接。当我在客户端上 运行 phpmyadmin 时我没有问题。
可能有安全防范措施。您可以尝试在 mysql.
中添加一个新的管理员帐户mysql> CREATE USER 'yourUser'@'localhost' IDENTIFIED BY 'some_pass';
mysql> GRANT ALL PRIVILEGES ON *.* TO 'yourUser'@'localhost'
-> WITH GRANT OPTION;
mysql> CREATE USER 'yourUser'@'%' IDENTIFIED BY 'some_pass';
mysql> GRANT ALL PRIVILEGES ON *.* TO 'yourUser'@'%'
-> WITH GRANT OPTION;
尝试在您的代码中新建用户。
希望对您有所帮助!