我在linux机箱上安装了mysql服务器IP = 192.168.1.100但是当我尝试连接到这个IP时它总是错误(111) . 但是使用localhost和127.0.0.1就可以了 .
beer@beer-laptop# ifconfig | grep "inet addr"
inet addr:127.0.0.1 Mask:255.0.0.0
inet addr:192.168.1.100 Bcast:192.168.1.255 Mask:255.255.255.0
beer@beer-laptop# mysql -ubeer -pbeer -h192.168.1.100
ERROR 2003 (HY000): Can't connect to MySQL server on '192.168.1.100' (111)
beer@beer-laptop# mysql -ubeer -pbeer -hlocalhost
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 160
Server version: 5.1.31-1ubuntu2 (Ubuntu)
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
mysql>
beer@beer-laptop# mysql -ubeer -pbeer -h127.0.0.1
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 161
Server version: 5.1.31-1ubuntu2 (Ubuntu)
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
mysql>
从另一台机器连接它也是错误111 .
another@another-laptop# mysql -ubeer -pbeer -h192.168.1.100
ERROR 2003 (HY000): Can't connect to MySQL server on '192.168.1.100' (111)
在这种情况下,如何使用localhost / 127.0.0.1和192.168.1.100之间的区别 . 我不知道如何从另一台机器连接到这个数据库 .
请帮忙 . 谢谢 .
4 回答
这可能意味着您的MySQL服务器只监听localhost接口 .
如果你有这样的行:
在my.cnf configuration file中,您应该对它们进行注释(在行的开头添加#),然后重新启动MySQL .
当然,要做到这一点,您必须是服务器的管理员 .
111表示连接被拒绝,这反过来意味着你的mysqld只监听
localhost
接口 .要更改它,您可能需要查看
my.cnf
文件的mysqld
部分中的bind-address
值 .如果以前的所有答案都没有给出任何解决方案,您应该检查您的用户权限 .
如果您可以
root
登录到mysql,那么您应该添加:然后尝试使用
mysql -ubeer -pbeer -h192.168.1.100
再次连接 . 它应该工作 .如果您正在运行cPanel / WHM,请确保IP在防火墙中列入白名单 . 您还需要将该IP添加到您尝试连接的cPanel帐户中的远程SQL IP列表中 .