dongsechuan0535 2013-07-26 07:40
浏览 41
已采纳

使用IP作为主机时,Php无法连接到MySQL工作台,但在使用localhost时工作正常

This is the error I get when using php code

"mysql_connect($host,$user,$password)", where $host="IP_of_my_system" :

Warning: mysql_connect(): Host 'xxx' is not allowed to connect to this MySQL server in C:\xampp\htdocs\mysqltest\insert.php on line 4

But when using localhost instead of IP, it works fine.

Why is this behavior?

  • 写回答

3条回答 默认 最新

  • douhuan9289 2013-07-26 08:21
    关注

    Its quite simple if you understand how Userid's work in MySQL.

    Each userid has a location associated with it from where that userid is allowed to logon from. This can be from anywhere % but normally its an ip address or set of ip addresses.

    So the userid you are using is probably setup to be allowed access from localhost and 127.0.0.1 and maybe ::1 all of which are ways of addressing the PC that the MySQL Server is running on.

    These should suffice so use localhost or 127.0.0.1 or change the userid definition in MySQL to be allowed to acess from 192.168.0.99 or whatever you ip address is, but using one of the alias's for this PC should be all you need. Using the alias's also helps when you move your code to another machine and/or MySQL server. I fyou use a specific IP it probably wont.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 phython如何实现以下功能?查找同一用户名的消费金额合并—
  • ¥15 孟德尔随机化怎样画共定位分析图
  • ¥18 模拟电路问题解答有偿速度
  • ¥15 CST仿真别人的模型结果仿真结果S参数完全不对
  • ¥15 误删注册表文件致win10无法开启
  • ¥15 请问在阿里云服务器中怎么利用数据库制作网站
  • ¥60 ESP32怎么烧录自启动程序
  • ¥50 html2canvas超出滚动条不显示
  • ¥15 java业务性能问题求解(sql,业务设计相关)
  • ¥15 52810 尾椎c三个a 写蓝牙地址