【发布时间】:2015-05-24 20:38:33
【问题描述】:
我可以通过 ssh 连接到 mysql 服务器。
# mysql -u username -h 185.2.3.80 -ppasword
输出是:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 280
Server version: 5.1.61 Source distribution
Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
我想用php连接mysql服务器:
<?php
$servername = "185.2.3.80";
$username = "username";
$password = "password";
// Create connection
$conn = new mysqli($servername, $username, $password);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
echo "Connected successfully";
?>
这是输出:
Could not connect: Can't connect to MySQL server on '185.2.3.80' (13)
我用 iptables 关闭防火墙并从 my.cnf 中删除 bind-address 和 skip-networking 。但无法连接 php 。
【问题讨论】: