[英]ERROR 2003 (HY000): Can't connect to MySQL server (111)
This question is related to the following questions:这个问题与以下问题有关:
I am configuring a new MySQL (5.1) server on my local machine.我正在我的本地机器上配置一个新的 MySQL (5.1) 服务器。 I need to provide remote access to the database.
我需要提供对数据库的远程访问。 I did the following steps:
我做了以下步骤:
Comment bind-address
in my.cnf:在 my.cnf 中注释
bind-address
:
# bind-address = 192.168.1.3
Grant privileges:授予特权:
GRANT ALL PRIVILEGES ON *.* TO 'nickruiz'@'%' IDENTIFIED BY PASSWORD 'xxxx';
Configure iptables for firewall为防火墙配置 iptables
sudo iptables -I INPUT -p udp --dport 3306 -j ACCEPT sudo iptables -I INPUT -p tcp --dport 3306 --syn -j ACCEPT sudo iptables-save
Restart mysql server sudo /etc/init.d/mysql restart
重启mysql服务器
sudo /etc/init.d/mysql restart
When testing, I get the following:测试时,我得到以下信息:
LAN:局域网:
mysql -h 192.168.1.3 -u nickruiz -p
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 95
Server version: 5.1.63-0ubuntu0.11.04.1 (Ubuntu)
Remote:偏僻的:
mysql -h 1xx.xx.4.136 -u nickruiz -p
ERROR 2003 (HY000): Can't connect to MySQL server on '1xx.xx.4.136' (111)
Clearly there's something wrong that's preventing me from being able to use my global IP address.很明显,有什么问题阻止了我使用我的全球 IP 地址。
Notes:笔记:
Any ideas?有任何想法吗?
Update: telnet doesn't seem to be working.更新:telnet 似乎不起作用。
telnet 192.168.1.3 3306
Trying 192.168.1.3...
Connected to 192.168.1.3.
Escape character is '^]'.
E
5.1.63-0ubuntu0.11.04.1,0g8!:@pX;]DyY0#\)SIConnection closed by foreign host.
Please check your listenning ports with :请检查您的侦听端口:
netstat -nat |grep :3306
If it show如果显示
tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN
Thats is ok for your remote connection.这对您的远程连接没问题。
But in this case i think you have但在这种情况下,我认为你有
tcp 0 192.168.1.3:3306 0.0.0.0:* LISTEN
Thats is ok for your remote connection.这对您的远程连接没问题。 You should also check your firewall (iptables if you centos/redhat)
你还应该检查你的防火墙(如果你是 centos/redhat 则是 iptables)
services iptables stop
for testing or use :用于测试或使用:
iptables -A input -p tcp -i eth0 --dport 3306 -m state NEW,ESTABLISHED -j ACCEPT
iptables -A output -p tcp -i eth0 --sport 3306 -m state NEW,ESTABLISHED -j ACCEPT
And another thing to check your grant permission for remote connection :还有一件事要检查您对远程连接的授予权限:
GRANT ALL ON *.* TO remoteUser@'remoteIpadress' IDENTIFIED BY 'my_password';
errno 111 is ECONNREFUSED, I suppose something is wrong with the router's DNAT. errno 111 是 ECONNREFUSED,我想路由器的 DNAT 有问题。
It is also possible that your ISP is filtering that port.您的 ISP 也可能正在过滤该端口。
Check that your remote host (ie the web hosting server you're trying to connect FROM) allows OUTGOING traffic on port 3306.检查您的远程主机(即您尝试连接的网络托管服务器)是否允许端口 3306 上的 OUTGOING 流量。
I saw the (100) error in this situation.我在这种情况下看到了 (100) 错误。 I could connect from my PC/Mac, but not from my website.
我可以从我的 PC/Mac 连接,但不能从我的网站连接。 The MySQL instance was accessible via the internet, but my hosting company wasn't allowing my website to connect to the database on port 3306.
MySQL 实例可通过 Internet 访问,但我的托管公司不允许我的网站连接到端口 3306 上的数据库。
Once I asked my hosting company to open my web hosting account up to outgoing traffic on port 3306, my website could connect to my remote database.一旦我要求我的托管公司在端口 3306 上打开我的网络托管帐户以发送流量,我的网站就可以连接到我的远程数据库。
/etc/mysql$ sudo nano my.cnf
Relevant portion that works for me:对我有用的相关部分:
#skip-networking
# Instead of skip-networking the default is now to listen only on
# localhost which is more compatible and is not less secure.
bind-address = MY_IP
MY_IP
can be found using ifconfig
or curl -L whatismyip.org |grep blue
.可以使用
ifconfig
或curl -L whatismyip.org |grep blue
找到MY_IP
。
Restart mysql to ensure the new config is loaded:重新启动 mysql 以确保加载新配置:
/etc/mysql$ sudo service mysql restart
如果你使用的系统是CentOS/RedHat,并且你安装MySQL的方式是rpm,那么/etc/文件夹下没有my.cnf,你可以使用:#whereis mysql #cd /usr/share/mysql/ cp -f /usr/share/mysql/my-medium.cnf /etc/my.cnf
我也有和你一样的问题,我用wireshark抓我发送的TCP包,发现用mysql
bin连接远程主机的时候,连接的是远程的3307端口,这是我在/etc/mysql/my.cnf
, 3307 是另一个项目 mysql 端口,但是我在my.cnf
[client] 部分更改了该配置,当我使用-P
选项指定 3306 端口时,就可以了。
我按照上面正确设置了我的绑定地址,但忘记重新启动 mysql 服务器(或重新启动):) face palm - 所以这对我来说是这个错误的根源!
I had the same problem trying to connect to a remote mysql db.我在尝试连接到远程 mysql 数据库时遇到了同样的问题。
I fixed it by opening the firewall on the db server to allow traffic through:我通过打开数据库服务器上的防火墙以允许流量通过来修复它:
sudo ufw allow mysql
Sometimes when you have special characters in password you need to wrap it in ''
characters, so to connect to db you could use:有时,当密码中有特殊字符时,您需要将其包装在
''
字符中,因此要连接到 db,您可以使用:
mysql -uUSER -p'pa$$w0rd'
I had the same error and this solution solved it.我有同样的错误,这个解决方案解决了它。
I had this same error and I didn't understand but I realized that my modem was using the same port as mysql.我有同样的错误,我不明白,但我意识到我的调制解调器使用与 mysql 相同的端口。 Well, I stop apache2.service by
sudo systemctl stop apache2.service
and restarted the xammp, sudo /opt/lampp/lampp start
好吧,我通过
sudo systemctl stop apache2.service
并重新启动 xammp, sudo /opt/lampp/lampp start
Just maybe, if you were not using a password for mysql yet you had, 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
, then you have to pass an empty string as the password只是也许,如果您还没有为 mysql 使用密码,那么
1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
,那么您必须传递一个空字符串作为密码
Not sure as cant see it in steps you mentioned.不确定在你提到的步骤中看不到它。
Please try FLUSH PRIVILEGES [Reloads the privileges from the grant tables in the mysql database]:请尝试FLUSH PRIVILEGES [从 mysql 数据库中的授权表重新加载权限]:
flush privileges;刷新权限;
You need to execute it after GRANT您需要在 GRANT 之后执行它
Hope this help!希望这有帮助!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.