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 在获取boss直聘的聊天的时候只能获取到前40条聊天数据
  • ¥20 关于URL获取的参数,无法执行二选一查询
  • ¥15 液位控制,当液位超过高限时常开触点59闭合,直到液位低于低限时,断开
  • ¥15 marlin编译错误,如何解决?
  • ¥15 有偿四位数,节约算法和扫描算法
  • ¥15 VUE项目怎么运行,系统打不开
  • ¥50 pointpillars等目标检测算法怎么融合注意力机制
  • ¥20 Vs code Mac系统 PHP Debug调试环境配置
  • ¥60 大一项目课,微信小程序
  • ¥15 求视频摘要youtube和ovp数据集