0

When I try to connect to a website database using the code:

$server = "domain";
$login = "username";
$password = "password";
$database = "databasename";
$port = 3307;
$con = mysqli_connect($server, $login, $password, $database, $port);

and have all warnings and errors enabled I get a message saying

Warning: mysqli_connect(): (HY000/2003): Can't connect to MySQL server on 'domain' (111) in 'path'

however when I change $server to localhost it works fine.

If it is blocking me through php unless I use localhost does anyone know why the HeidiSQL or MySQL Administrator clients can connect using the domain?

4

1 回答 1

0

我从您的问题陈述中了解到,您无法使用域或 IP 地址连接到 MySQL 服务器。要解决它,首先您需要向用户授予数据库访问权限。结帐下面的 sql 这将为您工作。

GRANT ALL PRIVILEGES ON `databasename`.* TO 'username'@'domain' IDENTIFIED BY 'password' WITH GRANT OPTION;

一旦授予用户权限,请检查您的 MySQL 配置设置。编辑您的 MySQL 配置文件 my.cnf 并设置以下提到的设置。

将绑定地址设置为 0.0.0.0 或将其注释掉:

bind-address            = 0.0.0.0
OR
# bind-address          = 127.0.0.1
于 2014-05-03T09:59:59.907 回答