简体   繁体   English

错误 2003 (HY000):无法连接到 MySQL 服务器 (111)

[英]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:我做了以下步骤:

  1. Comment bind-address in my.cnf:在 my.cnf 中注释bind-address

     # bind-address = 192.168.1.3
  2. Grant privileges:授予特权:

     GRANT ALL PRIVILEGES ON *.* TO 'nickruiz'@'%' IDENTIFIED BY PASSWORD 'xxxx';
  3. Set port forwarding on router (TCP and UDP, port 3306, 192.168.1.3)在路由器上设置端口转发(TCP 和 UDP,端口 3306、192.168.1.3)
  4. 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
  5. 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:笔记:

  • I've tried testing the remote connection on the same machine and also via SSH from a remote machine.我试过在同一台机器上测试远程连接,也试过从远程机器通过 SSH 测试。
  • I'm not sure if my ISP has given me a static IP.我不确定我的 ISP 是否给了我一个静态 IP。

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 .可以使用ifconfigcurl -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.

相关问题 错误 2003 (HY000):无法连接到“127.0.0.1”上的 MySQL 服务器 (111) - ERROR 2003 (HY000): Can't connect to MySQL server on '127.0.0.1' (111) 错误2003(HY000):无法连接到[IP]上的MySQL服务器(111“连接被拒绝”) - ERROR 2003 (HY000): Can't connect to MySQL server on [IP] (111 “Connection refused”) ERROR 2003(HY000):无法连接到'hostname'上的MySQL服务器(111) - ERROR 2003 (HY000): Can't connect to MySQL server on 'hostname' (111) 错误 2003 (HY000):无法连接到“127.0.0.1:3306”上的 MySQL 服务器 (111) - ERROR 2003 (HY000): Can't connect to MySQL server on '127.0.0.1:3306' (111) Gitlab-ci 运行 mysql docker 并连接错误 ERROR 2003 (HY000): Can't connect to MySQL server on 'localhost' (111) - Gitlab-ci running mysql docker and connect it with error ERROR 2003 (HY000): Can't connect to MySQL server on 'localhost' (111) mysqli_connect():(HY000 / 2003):无法连接到“域名”上的MySQL服务器(111) - mysqli_connect(): (HY000/2003): Can't connect to MySQL server on 'domain name' (111) mysql.connector.errors.DatabaseError: 2003 (HY000): 无法连接到“127.0.0.1”上的 MySQL 服务器 (111) - mysql.connector.errors.DatabaseError: 2003 (HY000): Can't connect to MySQL server on '127.0.0.1' (111) $ mysql -u root -p -h 127.0.0.1输入密码:ERROR 2003(HY000):无法连接到'127.0.0.1'上的MySQL服务器(111) - $ mysql -u root -p -h 127.0.0.1 Enter password: ERROR 2003 (HY000): Can't connect to MySQL server on '127.0.0.1' (111) Zend框架1.11-SQLSTATE [HY000] [2003]无法连接到“本地主机”上的MySQL服务器(111) - Zend framework 1.11 - SQLSTATE[HY000] [2003] Can't connect to MySQL server on 'localhost' (111) SQLSTATE [HY000] [2003]无法连接到MySQL服务器 - SQLSTATE[HY000] [2003] Can't connect to MySQL server
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM