gpt4 book ai didi

php MySql 连接错误

转载 作者:行者123 更新时间:2023-11-29 03:34:58 26 4
gpt4 key购买 nike

我有以下 php 代码来连接到我的 mysql 数据库。

mysql_connect( "myserver.com" , "root", "redhat","datastore") or die(mysql_error()); 

当我运行这段代码时,我收到错误消息:

Warning: mysql_connect(): Host '10.21.21.10' is not allowed to connect to this MySQL server in C:\xampp\htdocs\inventory\net.php on line 20
Host '10.21.21.10' is not allowed to connect to this MySQL server

但是当我在命令提示符下 ping myserver.com 时,myserver.com 的 IP 为 10.25.15.95

,所以我将代码修改为:

mysql_connect( "10.21.21.10" , "root", "redhat","datastore") or die(mysql_error()); 

重复同样的错误。

然后我将我的代码更改为:

mysql_connect( "10.25.15.95" , "root", "redhat","datastore") or die(mysql_error()); 

错误是

Warning: mysql_connect(): A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond. in C:\xampp\htdocs\inventory\net.php on line 20
A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.

请帮我解决这个问题..

提前致谢...

最佳答案

在你的 mysql 服务器上:

mysql> use mysql;   

mysql> CREATE USER 'root'@'client_ipaddress' IDENTIFIED BY 'redhat';

mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'client_ipaddress' WITH GRANT OPTION;

关于php MySql 连接错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23733626/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com