日期:2014-05-16  浏览次数:20419 次

PHP使用IP地址连接MySQL数据库

我们通常测试的时候都是用mysql_connect("localhost","usrname","password");的方式来连接MySQL数据库的,

如果我们要通过其他主机使用IP地址来连接MySQL数据库的时候,就需要修改MySQL的配置文件/etc/mysql/my.cnf,否则会出现这样的错误提示:

can t connect to mysql server on 111 

skip-external-locking
#
# Instead of skip-networking the default is now to listen only on
# localhost which is more compatible and is not less secure.
#bind-address           = 127.0.0.1 //这一行是要注释掉的

只要注释掉这一行bind-address之后再重启mysql就可以通过其他机器使用IP地址来连接mysql了。