我是靠谱客的博主 优美天空,最近开发中收集的这篇文章主要介绍记录mysql数据库连接数过大问题Too many connections,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

  转载自:http://www.5180it.com/bbs/admin/1/106.html

 

周末放假,突然收到短信提示“服务器故障”,顿时紧张起来,毕竟是正式环境。

 

回家,查看发现如下错误

 

com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: Data source rejected establishment of connection,  message from server: "Too many connections"

at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[na:1.8.0_144]

at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) ~[na:1.8.0_144]

at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) ~[na:1.8.0_144]

at java.lang.reflect.Constructor.newInstance(Constructor.java:423) ~[na:1.8.0_144]

at com.mysql.jdbc.Util.handleNewInstance(Util.java:425) ~[mysql-connector-java-5.1.41.jar!/:5.1.41]

at com.mysql.jdbc.Util.getInstance(Util.java:408) ~[mysql-connector-java-5.1.41.jar!/:5.1.41]

at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:918) ~[mysql-connector-java-5.1.41.jar!/:5.1.41]

at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:897) ~[mysql-connector-java-5.1.41.jar!/:5.1.41]

at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:886) ~[mysql-connector-java-5.1.41.jar!/:5.1.41]

at com.mysql.jdbc.MysqlIO.doHandshake(MysqlIO.java:1040) ~[mysql-connector-java-5.1.41.jar!/:5.1.41]

at com.mysql.jdbc.ConnectionImpl.coreConnect(ConnectionImpl.java:2205) ~[mysql-connector-java-5.1.41.jar!/:5.1.41]

at com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2236) ~[mysql-connector-java-5.1.41.jar!/:5.1.41]

at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2035) ~[mysql-connector-java-5.1.41.jar!/:5.1.41]

at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:790) ~[mysql-connector-java-5.1.41.jar!/:5.1.41]

at com.mysql.jdbc.JDBC4Connection.<init>(JDBC4Connection.java:47) ~[mysql-connector-java-5.1.41.jar!/:5.1.41]

at sun.reflect.GeneratedConstructorAccessor137.newInstance(Unknown Source) ~[na:na]

at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) ~[na:1.8.0_144]

at java.lang.reflect.Constructor.newInstance(Constructor.java:423) ~[na:1.8.0_144]

at com.mysql.jdbc.Util.handleNewInstance(Util.java:425) ~[mysql-connector-java-5.1.41.jar!/:5.1.41]

at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:400) ~[mysql-connector-java-5.1.41.jar!/:5.1.41]

at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:330) ~[mysql-connector-java-5.1.41.jar!/:5.1.41]

at com.alibaba.druid.filter.FilterChainImpl.connection_connect(FilterChainImpl.java:156) ~[druid-1.1.20.jar!/:1.1.20]

at com.alibaba.druid.filter.FilterAdapter.connection_connect(FilterAdapter.java:787) ~[druid-1.1.20.jar!/:1.1.20]

at com.alibaba.druid.filter.FilterEventAdapter.connection_connect(FilterEventAdapter.java:38) ~[druid-1.1.20.jar!/:1.1.20]

at com.alibaba.druid.filter.FilterChainImpl.connection_connect(FilterChainImpl.java:150) ~[druid-1.1.20.jar!/:1.1.20]

at com.alibaba.druid.filter.FilterAdapter.connection_connect(FilterAdapter.java:787) ~[druid-1.1.20.jar!/:1.1.20]

at com.alibaba.druid.filter.FilterChainImpl.connection_connect(FilterChainImpl.java:150) ~[druid-1.1.20.jar!/:1.1.20]

at com.alibaba.druid.filter.stat.StatFilter.connection_connect(StatFilter.java:218) ~[druid-1.1.20.jar!/:1.1.20]

at com.alibaba.druid.filter.FilterChainImpl.connection_connect(FilterChainImpl.java:150) ~[druid-1.1.20.jar!/:1.1.20]

at com.alibaba.druid.pool.DruidAbstractDataSource.createPhysicalConnection(DruidAbstractDataSource.java:1645) ~[druid-1.1.20.jar!/:1.1.20]

at com.alibaba.druid.pool.DruidAbstractDataSource.createPhysicalConnection(DruidAbstractDataSource.java:1709) ~[druid-1.1.20.jar!/:1.1.20]

at com.alibaba.druid.pool.DruidDataSource$CreateConnectionThread.run(DruidDataSource.java:2715) ~[druid-1.1.20.jar!/:1.1.20]

 

一看日志就猜到是数据库连接数问题,虽然是正式环境,但也没多少用户的。
最直接的方法,重启项目,但发现还是不行。。。

 

后来通过下面查看mysql的最大连接数,只有151

 

SHOW VARIABLES LIKE '%max_connections%';  

 

然后就把最大连接数设置大点

 set GLOBAL max_connections=500;

 

果然就好了,回去查看哪里访问比较多,还有是否没有释放连接

 

  转载自:http://www.5180it.com/bbs/admin/1/106.html

最后

以上就是优美天空为你收集整理的记录mysql数据库连接数过大问题Too many connections的全部内容,希望文章能够帮你解决记录mysql数据库连接数过大问题Too many connections所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(73)

评论列表共有 0 条评论

立即
投稿
返回
顶部