【问题标题】:Can't connect to mysql when I changed its port number rather than 3306当我更改其端口号而不是 3306 时无法连接到 mysql
【发布时间】:2018-06-01 10:51:57
【问题描述】:

当我尝试将 mysql 的端口号更改为 9094 而不是 3306 时,我有点错误。但是当我使用 3306 时,我可以获取它的数据。我很确定我将与我的 Java Web App 的所有端口连接从 3306 更改为 9094,但仍然有错误。

这是错误..

com.mysql.jdbc.exceptions.jdbc4.CommunicationsException:通信链路故障

这是我的 jdbc.properties

jdbc.driverClassName=com.mysql.jdbc.Driver
jdbc.url=jdbc:mysql://127.0.0.1:9094/hnlmnl_db
jdbc.username=infordev
jdbc.password=infordev

这是我的小服务程序

<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
    <property name="driverClassName" value="${jdbc.driverClassName}" />
    <property name="url" value="${jdbc.url}" />
    <property name="username" value="${jdbc.username}" />
    <property name="password" value="${jdbc.password}" />
</bean>

但仍然出现连接错误..

有什么帮助吗?

谢谢!

这里是调试信息

org.springframework.web.util.NestedServletException: Request processing failed; nested exception is 
org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection; nested exception is org.apache.commons.dbcp.SQLNestedException: Cannot create PoolableConnectionFactory (Communications link failure

The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.)

org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection; nested exception is org.apache.commons.dbcp.SQLNestedException: 
Cannot create PoolableConnectionFactory (Communications link failure

The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.)

org.apache.commons.dbcp.SQLNestedException: Cannot create 
PoolableConnectionFactory (Communications link failure

The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.)

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

The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.

java.net.ConnectException: Connection refused: connect

【问题讨论】:

  • 你必须在 mysql 中更改它,它会自行检查这个线程:stackoverflow.com/questions/29866204/…
  • @AmrBerag 我在 my.ini 中更改了它的配置
  • @JamesAllen 你重启了mysql服务吗
  • 你重启过等吗?
  • 你有没有安装某种防火墙的机会?一些防病毒防火墙甚至会影响本地主机。

标签: java mysql spring


【解决方案1】:

连接被拒绝通常意味着没有服务正在侦听您尝试连接的服务器/端口:

  • 检查 MySQL 服务是否正在运行。如果没有,请启动它。
  • 检查它是否实际上正在监听 127.0.0.1:9094:
    • 通过使用netstat -a
    • 通过使用命令行mysql工具或具有上述IP/端口的工作台
    • 通过尝试使用 telnet 或 netcat 或类似工具连接到上述 IP/端口。

如果服务正在运行但没有侦听该 IP/端口,那么您需要修复 mysql 服务器配置。检查文档。

如果服务正在运行并在该 IP/端口上侦听,则表明存在网络问题;例如一些奇怪的防火墙。 (你永远不需要在 127.0.0.1 上做任何防火墙 ....)

【讨论】:

    猜你喜欢
    • 2017-11-15
    • 2017-11-20
    • 2015-05-11
    • 2019-06-13
    • 1970-01-01
    • 1970-01-01
    • 2020-09-29
    • 2011-09-02
    • 1970-01-01
    相关资源
    最近更新 更多