Linux 无法连接到 MySQL 服务器错误 111
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1420839/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Can't connect to MySQL server error 111
提问by wearetherock
I installed mysql server on linux box IP = 192.168.1.100 but when i try to connect to this IP it alway error(111). but use localhost and 127.0.0.1 is OK.
我在 linux box IP = 192.168.1.100 上安装了 mysql 服务器,但是当我尝试连接到这个 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>
Connect from another machine it also error 111.
从另一台机器连接它也会出现错误 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)
How difference between use localhost/127.0.0.1 and 192.168.1.100 in this case. I don't know how to connect to this database from another machine.
在这种情况下使用 localhost/127.0.0.1 和 192.168.1.100 之间的区别。我不知道如何从另一台机器连接到这个数据库。
Help please. Thank.
请帮忙。谢谢。
采纳答案by Pascal MARTIN
It probably means that your MySQL server is only listening the localhost interface.
这可能意味着您的 MySQL 服务器仅侦听 localhost 接口。
If you have lines like this :
如果你有这样的行:
bind-address = 127.0.0.1
In your my.cnf
configuration file, you should comment them (add a # at the beginning of the lines), and restart MySQL.
在您的my.cnf
配置文件中,您应该对它们进行注释(在行的开头添加 #),然后重新启动 MySQL。
sudo service mysql restart
Of course, to do this, you must be the administrator of the server.
当然,要做到这一点,您必须是服务器的管理员。
回答by Michael Krelin - hacker
111 means connection refused, which in turn means that your mysqld only listens to the localhost
interface.
111 表示连接被拒绝,这反过来意味着你的 mysqld 只监听localhost
接口。
To alter it you may want to look at the bind-address
value in the mysqld
section of your my.cnf
file.
要更改它,您可能需要查看文件部分中的bind-address
值。mysqld
my.cnf
回答by xnome
If all the previous answers didn't give any solution, you should check your user privileges.
如果之前的所有答案都没有给出任何解决方案,您应该检查您的用户权限。
If you could login as root
to mysql
then you should add this:
如果您可以登录root
到 mysql,那么您应该添加以下内容:
CREATE USER 'root'@'192.168.1.100' IDENTIFIED BY '***';
GRANT ALL PRIVILEGES ON * . * TO 'root'@'192.168.1.100' IDENTIFIED BY '***' WITH GRANT OPTION MAX_QUERIES_PER_HOUR 0 MAX_CONNECTIONS_PER_HOUR 0 MAX_UPDATES_PER_HOUR 0 MAX_USER_CONNECTIONS 0 ;
Then try to connect again using mysql -ubeer -pbeer -h192.168.1.100
. It should work.
然后尝试使用 再次连接mysql -ubeer -pbeer -h192.168.1.100
。它应该工作。
回答by Dragos.
If you're running cPanel/WHM, make sure that IP is whitelisted in the firewall. You will als need to add that IP to the remote SQL IP list in the cPanel account you're trying to connect to.
如果您正在运行 cPanel/WHM,请确保 IP 已在防火墙中列入白名单。您还需要将该 IP 添加到您尝试连接的 cPanel 帐户中的远程 SQL IP 列表中。