Host '192.168.1.254' is not错误解决办法

本文记录了一次解决MySQL服务器不允许外部IP连接的问题经历。通过更改连接代码中的IP地址为127.0.0.1,成功实现了从PHP代码中连接MySQL数据库。此问题常见于开发环境中,对于遇到类似情况的开发者具有一定的参考价值。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

哎!今天这个问题搞死我了。百度和优快云都发下。需要以后大家遇到这个问题可以很快解决!!!

Warning: mysql_connect() [function.mysql-connect]: Host '192.168.1.254' is not allowed to connect to this MySQL server in E:/www/xnwenn/wb/phpxd/min/dbclass.php on line 25

Warning: mysql_select_db(): supplied argument is not a valid MySQL-Link resource in E:/www/xnwenn/wb/phpxd/min/dbclass.php online 31

说起来也很奇怪!我用PHPMYADMIN可以登陆,但是用代码确连接不上。

后来就一直在找技术文章,看看有人写这过这样的php文章么。找了半天没。

后来自己就慢慢测试!连接代码写了几种还是一样,。。

后来把IP改了下就好了

解决办法:

<?php
$conn=mysql_connect("58.49.199.186","hudfsfazi521","DAIdsfdsfsYUAN")or die ("连接失败 ".mysql_error());  //创建数据库连接
mysql_select_db("data123",$conn) or die ("无法选择 ".mysql_error()); //选择要操作的数据库
?>

上面是我的代码只要把IP改成127.0.0.1就可以了。

<?php
$conn=mysql_connect("127.0.0.1","hudfsfazi521","DAIdsfdsfsYUAN")or die ("连接失败 ".mysql_error());  //创建数据库连接
mysql_select_db("data123",$conn) or die ("无法选择 ".mysql_error()); //选择要操作的数据库
?>

原因是因为:MySQL数据库不允许其它电脑(非虚拟主机本身)用IP地址访问它

 

这个配置单有问题吗:# dhcpd.conf # # Sample configuration file for ISC dhcpd # # Attention: If /etc/ltsp/dhcpd.conf exists, that will be used as # configuration file instead of this file. # # option definitions common to all supported networks... # option domain-name "example.org"; # option domain-name-servers ns1.example.org, ns2.example.org; default-lease-time 60; max-lease-time 120; # The ddns-updates-style parameter controls whether or not the server will # attempt to do a DNS update when a lease is confirmed. We default to the # behavior of the version 2 packages ('none', since DHCP v2 didn't # have support for DDNS.) ddns-update-style none; # If this DHCP server is the official DHCP server for the local # network, the authoritative directive should be uncommented. authoritative; # Use this to send dhcp log messages to a different log file (you also # have to hack syslog.conf to complete the redirection). #log-facility local7; # No service will be given on this subnet, but declaring it helps the # DHCP server to understand the network topology. #subnet 10.152.187.0 netmask 255.255.255.0 { #} # This is a very basic subnet declaration. subnet 192.168.50.0 netmask 255.255.255.0 { range 192.168.50.40 192.168.50.50; option routers 192.168.50.10; host soho{ hardware ethernet 08:00:07:26:c0:a5; fixed-address 192.168.50.40; } } # This declaration allows BOOTP clients to get dynamic addresses, # which we don't really recommend. #subnet 10.254.239.32 netmask 255.255.255.224 { # range dynamic-bootp 10.254.239.40 10.254.239.60; # option broadcast-address 10.254.239.31; # option routers rtr-239-32-1.example.org; #} # A slightly different configuration for an internal subnet. #subnet 10.5.5.0 netmask 255.255.255.224 { # range 10.5.5.26 10.5.5.30; # option domain-name-servers ns1.internal.example.org; # option domain-name "internal.example.org"; # option subnet-mask 255.255.255.224; # option routers 10.5.5.1; # option broadcast-address 10.5.5.31; # default-lease-time 600; # max-lease-time 7200; #} # Hosts which require special configuration options can be listed in # host statements. If no address is specified, the address will be # allocated dynamically (if possible), but the host-specific information # will still come from the host declaration. #host passacaglia { # hardware ethernet 0:0:c0:5d:bd:95; # filename "vmunix.passacaglia"; # server-name "toccata.example.com"; #} # Fixed IP addresses can also be specified for hosts. These addresses # should not also be listed as being available for dynamic assignment. # Hosts for which fixed IP addresses have been specified can boot using # BOOTP or DHCP. Hosts for which no fixed address is specified can only # be booted with DHCP, unless there is an address range on the subnet # to which a BOOTP client is connected which has the dynamic-bootp flag # set. # You can declare a class of clients and then do address allocation # based on that. The example below shows a case where all clients # in a certain class get addresses on the 10.17.224/24 subnet, and all # other clients get addresses on the 10.0.29/24 subnet. #class "foo" { # match if substring (option vendor-class-identifier, 0, 4) = "SUNW"; #} #shared-network 224-29 { # subnet 10.17.224.0 netmask 255.255.255.0 { # option routers rtr-224.example.org; # } # subnet 10.0.29.0 netmask 255.255.255.0 { # option routers rtr-29.example.org; # } # pool { # allow members of "foo"; # range 10.17.224.10 10.17.224.250; # } # pool { # deny members of "foo"; # range 10.0.29.10 10.0.29.230; # } #}
最新发布
07-25
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值