我们目前在我们的生产服务器上存在一个主要问题。我们在一台服务器上有一个MySQL DB(Ubuntu 14.04和MySQL版本5.5.57)。
我们有另一台服务器,所有应用程序都在服务器1上与数据库通信。 5天后,我们不断在第二台服务器上出现此错误:
05-09-2017 00:00:01 WARN com.mchange.v2.resourcepool.BasicResourcePool$ScatteredAcquireTask@623841b8 -- Acquisition Attempt Failed!!! Clearing pending acquires. While trying to acquire a needed new resource, we failed to succeed more than the maximum number of allowed acquisition attempts (30). Last acquisition attempt exception:
com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: Could not create connection to database server. Attempted reconnect 3 times. Giving up.
at sun.reflect.GeneratedConstructorAccessor32.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:408)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:411)
at com.mysql.jdbc.Util.getInstance(Util.java:386)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1015)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:989)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:975)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:920)
at com.mysql.jdbc.ConnectionImpl.connectWithRetries(ConnectionImpl.java:2395)
at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2316)
at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:834)
at com.mysql.jdbc.JDBC4Connection.<init>(JDBC4Connection.java:47)
at sun.reflect.GeneratedConstructorAccessor19.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:408)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:411)
at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:416)
at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:347)
at com.mchange.v2.c3p0.DriverManagerDataSource.getConnection(DriverManagerDataSource.java:146)
at com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:195)
at com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:184)
at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool$1PooledConnectionResourcePoolManager.acquireResource(C3P0PooledConnectionPool.java:200)
at com.mchange.v2.resourcepool.BasicResourcePool.doAcquire(BasicResourcePool.java:1086)
at com.mchange.v2.resourcepool.BasicResourcePool.doAcquireAndDecrementPendingAcquiresWithinLockOnSuccess(BasicResourcePool.java:1073)
at com.mchange.v2.resourcepool.BasicResourcePool.access$800(BasicResourcePool.java:44)
at com.mchange.v2.resourcepool.BasicResourcePool$ScatteredAcquireTask.run(BasicResourcePool.java:1810)
at com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread.run(ThreadPoolAsynchronousRunner.java:648)
Caused by: java.sql.SQLException: null, message from server: "Host 'IP_ADDRESS' is blocked because of many connection errors; unblock with 'mysqladmin flush-hosts'"
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1078)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:989)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:975)
at com.mysql.jdbc.MysqlIO.doHandshake(MysqlIO.java:1114)
at com.mysql.jdbc.ConnectionImpl.coreConnect(ConnectionImpl.java:2493)
at com.mysql.jdbc.ConnectionImpl.connectWithRetries(ConnectionImpl.java:2334)
我们已经尝试了5天来解决这个问题,但是每次我们重新启动mysql几个小时,然后错误再次启动。我已将max_connect_errors从10增加到50,但这只会延长错误。
然后我们还将日志级别调整为2,但我们在错误日志中看到的唯一内容是中止连接,没有被拒绝&#39;连接。
有什么办法可以看到实际的连接错误吗?请帮忙解决这个问题,我不知道如何解决。我们也没有DBA,所以它只是一个不是数据库专家的开发团队。
编辑:该应用程序是一个Java maven应用程序,使用hibernate连接到数据库。这是hibernate配置文件:
<hibernate-configuration>
<session-factory>
<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.connection.username">USERNAME_HERE</property>
<property name="hibernate.connection.password">PASSWORD_HERE</property>
<property name="hibernate.connection.url">jdbc:mysql://SERVER_HERE:3306/voda_soccer?zeroDateTimeBehavior=convertToNull</property>
<property name="hibernate.connection.autoReconnect">true</property>
<property name="hibernate.dialect">org.hibernate.dialect.MySQLInnoDBDialect</property>
<property name="hibernate.temp.use_jdbc_metadata_defaults">false</property>
<property name="show_sql">false</property>
<property name="hibernate.c3p0.min_size">5</property>
<property name="hibernate.c3p0.max_size">20</property>
<property name="hibernate.c3p0.timeout">300</property>
<property name="hibernate.c3p0.max_statements">50</property>
<property name="hibernate.c3p0.idle_test_period">3000</property>
<mapping class="com.myapp.sms.producer.entity.Customer"></mapping>
<mapping class="com.myapp.sms.producer.entity.Gifting"></mapping>
<mapping class="com.myapp.sms.producer.entity.BulkCampaign"></mapping>
</session-factory>
我们总是关闭finally块中的连接:
} finally {
if (session != null) {
try {
session.close();
} catch (Exception e) {}
}
session = null;
}
我知道我们可以刷新主机或重新启动MySQL,但我不能在生产服务器中一直这样做。我想找出为什么我们得到连接错误以及在哪里看到它们?
答案 0 :(得分:0)
似乎存在连接泄漏,或者您可能长时间运行查询以阻止其他代码段获取连接。
根据您使用的数据源工具(c3p0,hikari等),您可以通过jmx(jsconsole,visual vm)监控您的池。
此外,您可以使用Flexy Pool进行一些监控。
Mysql workbench还提供了一些有用的工具,以便获得有关负责的操作的更多信息。