一尘不染

远程mysql连接

mysql

我一直在localhost上建立一个网络,当我尝试在主机上移动它时,它显示了很多错误。似乎无法连接到我的本地数据库。这是代码:

$host = "myip";
$user = "root";
$pass = "";
$db = "mydatabase";

mysql_connect($host, $user, $pass);
mysql_select_db($db);
$on = mysql_fetch_row(mysql_query("SELECT COUNT(online) FROM characters WHERE online=1"));
echo "<br>Online: $on[0]<br><br>";

这是输出:

Warning: mysql_connect() [function.mysql-connect]: Host 'myip' is not allowed to connect to this MySQL server in * on line 46

Warning: mysql_fetch_row(): supplied argument is not a valid MySQL result resource in * on line 48

Online:

感谢帮助


阅读 241

收藏
2020-05-17

共1个答案

一尘不染

这是mysql用户权限问题。例如,使用phpmyadmin创建一个新用户,如果从localhost连接,则将其主机设置为localhost;如果从外部连接,则将其主机设置为%。

2020-05-17