mysql 应用程序连接到端口 3306 的问题

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3480267/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 16:51:34  来源:igfitidea点击:

Issue connecting to port 3306 for mysql application

mysqltelnet

提问by Walker Holahan

The Java application I am working with is supposed to write its resulting data to a mysql database, but whenever I run it, I get the following exception:

我正在使用的 Java 应用程序应该将其结果数据写入 mysql 数据库,但是每当我运行它时,我都会收到以下异常:

com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure

With the following cause:

由于以下原因:

Caused by: java.net.ConnectException: Connection refused

Naturally, my next step was to test the port that mysql was attempting to connect on (3306).

当然,我的下一步是测试 mysql 试图连接的端口 (3306)。

$ telnet localhost 3306 
Trying 127.0.0.1...
telnet: Unable to connect to remote host: Connection refused

My next step was to see if port 3306 was listening at all.

我的下一步是查看端口 3306 是否正在侦听。

$ netstat -an|grep 3306
tcp        0      0 69.164.214.18:3306      0.0.0.0:*               LISTEN

So in summary, the port is listening but not accepting connections? I must admit, I do not know a whole lot about this, but does anybody know what is going on here?

总而言之,端口正在侦听但不接受连接?我必须承认,我对此知之甚少,但有人知道这里发生了什么吗?

采纳答案by Walker Holahan

I figured it out. I needed to connect to mysql externally, but my program was trying to access it locally.

我想到了。我需要从外部连接到 mysql,但我的程序试图在本地访问它。

回答by Go Namhyeon

Checklist:

清单:

  1. Firewall rule: If your server deny/not allow 3306 port, can not connect it.
  2. Bind Address: if your bind address are 127.0.0.1 in MySQL configuration, you must change to 0.0.0.0 in [mysqld] on /etc/mysql/my.cnf
  3. Restart Service: you have to run command 'service mysql restart'
  1. 防火墙规则:如果您的服务器拒绝/不允许 3306 端口,则无法连接。
  2. 绑定地址:如果你的绑定地址在 MySQL 配置中是 127.0.0.1,你必须在 /etc/mysql/my.cnf 上的 [mysqld] 中更改为 0.0.0.0
  3. 重新启动服务:您必须运行命令“service mysql restart”

Good Luck.

祝你好运。