【MySQL】使用JDBC时,无法连接远程MySQL数据库

在尝试使用JDBC连接远程MySQL数据库时遇到连接失败的问题,经过排查,包括检查配置文件、用户权限、防火墙设置、服务状态以及查阅官方文档,发现是MySQL配置文件中的bind-address设置为127.0.0.1导致的。通过注释该配置,重启MySQL服务,成功实现了远程连接。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

使用JDBC时,无法连接远程MySQL数据库



问题

今天连接MySQL的时候,程序很久没有反应,在过了几分钟后向我抛出了一堆异常:

警告: Having failed to acquire a resource, com.mchange.v2.resourcepool.BasicResourcePool@3d121db3 is interrupting all Threads waiting on a resource to check out. Will try again in response to new client requests.

java.sql.SQLException: Connections could not be acquired from the underlying database!

    at com.mchange.v2.sql.SqlUtils.toSQLException(SqlUtils.java:118)
    at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool.checkoutPooledConnection(C3P0PooledConnectionPool.java:692)
    at com.mchange.v2.c3p0.impl.AbstractPoolBackedDataSource.getConnection(AbstractPoolBackedDataSource.java:140)
    at cn.wjinlong.spring.jdbc.JDBCTest.testDataSource(JDBCTest.java:43)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
    at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
    at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
    at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
    at org.junit.runners
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值