• 欢迎光临~

记一次节点被mysql锁定的异常处理

开发技术 开发技术 2022-12-14 次浏览

参考:https://blog.csdn.net/weixin_34293141/article/details/93057113

同事反馈公司的一个java客户端工具运行异常,后台log如下:

2022-12-08 10:52:28 WARN BasicResourcePool:223 - com.mchange.v2.resourcepool.BasicResourcePool$ScatteredAcquireTask@18afde8 -- 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: java.sql.SQLException: null, message from server: "Host 'VBJVDI00378.test.com' is blocked because of many connection errors; unblock with 'mysqladmin flush-hosts'" at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1055) at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:956) at com.mysql.jdbc.MysqlIO.doHandshake(MysqlIO.java:1095) at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2031) at com.mysql.jdbc.ConnectionImpl.(ConnectionImpl.java:718) at com.mysql.jdbc.JDBC4Connection.(JDBC4Connection.java:46) at sun.reflect.GeneratedConstructorAccessor6.newInstance(Unknown Source) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source) at java.lang.reflect.Constructor.newInstance(Unknown Source) at com.mysql.jdbc.Util.handleNewInstance(Util.java:406) at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:302) at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:282) at com.mchange.v2.c3p0.DriverManagerDataSource.getConnection(DriverManagerDataSource.java:175) at com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:220) at com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:206) at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool$1PooledConnectionResourcePoolManager.acquireResource(C3P0PooledConnectionPool.java:203) at com.mchange.v2.resourcepool.BasicResourcePool.doAcquire(BasicResourcePool.java:1138) at com.mchange.v2.resourcepool.BasicResourcePool.doAcquireAndDecrementPendingAcquiresWithinLockOnSuccess(BasicResourcePool.java:1125) at com.mchange.v2.resourcepool.BasicResourcePool.access$700(BasicResourcePool.java:44) at com.mchange.v2.resourcepool.BasicResourcePool$ScatteredAcquireTask.run(BasicResourcePool.java:1870) at com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread.run(ThreadPoolAsynchronousRunner.java:696)

log重点:

2022-12-08 10:52:28 WARN BasicResourcePool:223 - com.mchange.v2.resourcepool.BasicResourcePool$ScatteredAcquireTask@18afde8 -- 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:
java.sql.SQLException: null, message from server: "Host 'VBJVDI00378.test.com' is blocked because of many connection errors; unblock with 'mysqladmin flush-hosts'"

根据重点log,可以找到以下几点:
1)问题:
Host 'VBJVDI00378.test.com' is blocked because of many connection errors
同一个ip在短时间连接MySQL服务失败次数超过max_connection_errors参数设定值(默认10),MySQL则认为是数据库出错,并且阻止了站点的链接。
2)解决方法一:
unblock with 'mysqladmin flush-hosts
终端中执行mysqladmin -uroot -p -h localhost flush-hosts
或者连接数据库后执行flush hosts
mysql>flush hosts
3)解决方法二:
进入数据库将max_connection_errors参数调高,或者修改my.cnf(需要重启MySQL)。

mysql>show variables like '%max_connection_errors%';
mysql>set global max_connect_errors = 1000;
mysql>show variables like '%max_connection_errors%';

注意:配置有master/slave主从数据库的要把主库和从库都修改一遍的。

程序员灯塔
转载请注明原文链接:记一次节点被mysql锁定的异常处理
喜欢 (0)