如何连接到网络上另一台计算机上主机上的mysql [英] how to connect to mysql on host on another computer on network
问题描述
对于
$conn = mysql_connect("192.168.0.235", "root", "") or
die("Could not connect: " . mysql_error());
mysql_select_db("crossdomaintest");
$result = mysql_query("SELECT * FROM testing");
while ($row = mysql_fetch_array($result, MYSQL_NUM)) {
echo $row[1].$row[2].$row[3]."<br/>";
}
mysql_free_result($result);
我得到
警告:mysql_connect()[function.mysql-connect]:不允许主机"192.168.0.167"连接到第3行的/var/www/test.php中的此MySQL服务器 无法连接:不允许主机"192.168.0.167"连接到该MySQL服务器
Warning: mysql_connect() [function.mysql-connect]: Host '192.168.0.167' is not allowed to connect to this MySQL server in /var/www/test.php on line 3 Could not connect: Host '192.168.0.167' is not allowed to connect to this MySQL server
我的IP是192.168.0.168
,我在Ubuntu 10.10
上使用LAMP
,而192.168.0.235
在windows 7
上使用XAMPP,我可以访问...235
上的所有站点,但不能从本地服务器访问数据库
And my IP is 192.168.0.168
and I am using LAMP
on Ubuntu 10.10
and 192.168.0.235
is using XAMPP on windows 7
i can access all sites on ...235
but not access database from my local-server.
有什么想法吗?
推荐答案
这与如何连接"无关.连接将完全相同.
关于如何设置远程服务器以允许来自IP的连接.
您在192.168.0.235上的数据库服务器上具有root特权吗?如果是这样,则必须在其上运行适当的GRANT PRIVILEGES查询.
如果不是,请让数据库管理员这样做
it's not about "how to connect". connecting would be all the same.
it's about how to setup remote server to allow connections from your IP.
do you have root privileges on the db server on 192.168.0.235? if so, you have to run appropriate GRANT PRIVILEGES query on it.
If not - ask a db admin to do that
我还建议不要使用root用户访问远程数据库.更好地创建另一个用户并给他适当的权限
I'd also advise not to use root user to access remote database. Better create another user and give him appropriate privileges
这篇关于如何连接到网络上另一台计算机上主机上的mysql的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!