Mysql的错误,待解决[已解决]Data source rejected establishment of connection message from server: "Too many connections"; [15:22:53,461] [CustomExceptionHandler,44] - Handle Exception:Hibernate operation: Cannot open connection; uncategorized SQLException for SQL [???]; SQL state [08004]; error code [1040]; Data source rejected establishment of connection message from server: "Too many connections"; nested exception is java.sql.SQLException: Data source rejected establishment of connection message from server: "Too many connections"
org.springframework.jdbc.UncategorizedSQLException: Hibernate operation: Cannot open connection; uncategorized SQLException for SQL [???]; SQL state [08004]; error code [1040]; Data source rejected establishment of connection message from server: "Too many connections"; nested exception is java.sql.SQLException: Data source rejected establishment of connection message from server: "Too many connections"
java.sql.SQLException: Data source rejected establishment of connection message from server: "Too many connections"
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:1997)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:1906)
at com.mysql.jdbc.MysqlIO.secureAuth411(MysqlIO.java:2535)
at com.mysql.jdbc.MysqlIO.doHandshake(MysqlIO.java:817)
at com.mysql.jdbc.Connection.createNewIO(Connection.java:1782)
at com.mysql.jdbc.Connection.<init>(Connection.java:450)
at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:411)
at java.sql.DriverManager.getConnection(DriverManager.java:525)
at java.sql.DriverManager.getConnection(DriverManager.java:140)
at org.springframework.jdbc.datasource.DriverManagerDataSource.getConnectionFromDriverManager(DriverManagerDataSource.java:291)
at org.springframework.jdbc.datasource.DriverManagerDataSource.getConnectionFromDriverManager(DriverManagerDataSource.java:277)
at org.springframework.jdbc.datasource.DriverManagerDataSource.getConnectionFromDriverManager(DriverManagerDataSource.java:259)
at org.springframework.jdbc.datasource.DriverManagerDataSource.getConnection(DriverManagerDataSource.java:241)
at org.springframework.orm.hibernate3.LocalDataSourceConnectionProvider.getConnection(LocalDataSourceConnectionProvider.java:80)
at org.hibernate.jdbc.ConnectionManager.openConnection(ConnectionManager.java:315)
at org.hibernate.jdbc.ConnectionManager.getConnection(ConnectionManager.java:109)
at org.hibernate.jdbc.AbstractBatcher.prepareQueryStatement(AbstractBatcher.java:105)
at org.hibernate.loader.Loader.prepareQueryStatement(Loader.java:1561)
at org.hibernate.loader.Loader.doQuery(Loader.java:661)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:224)
at org.hibernate.loader.Loader.doList(Loader.java:2150)
at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2029)
at org.hibernate.loader.Loader.list(Loader.java:2024)
at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:369)
at org.hibernate.hql.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:300)
at org.hibernate.engine.query.HQLQueryPlan.performList(HQLQueryPlan.java:146)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1093)
at org.hibernate.impl.QueryImpl.list(QueryImpl.java:79)
at com.easou.framework.dao.hibernate.BaseDAOHibernate.pageListQuery(BaseDAOHibernate.java:164)
at com.vitamin.cn.manager.news.dao.hibernate.NewsDAOHibernate.searchNews(NewsDAOHibernate.java:38)
at com.vitamin.cn.manager.news.bl.impl.NewsManagerImpl.searchNews(NewsManagerImpl.java:24)
at com.vitamin.cn.manager.news.action.NewsAction.listNews(NewsAction.java:88)
at com.vitamin.cn.manager.news.action.NewsAction.execute(NewsAction.java:35)
at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:419)
at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:224)
at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1196)
at org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:414)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:689)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
at com.easou.framework.util.SetCharacterEncodingFilter.doFilter(SetCharacterEncodingFilter.java:88)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:524)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
at org.apache.jk.server.JkCoyoteHandler.invoke(JkCoyoteHandler.java:199)
at org.apache.jk.common.HandlerRequest.invoke(HandlerRequest.java:282)
at org.apache.jk.common.ChannelSocket.invoke(ChannelSocket.java:767)
at org.apache.jk.common.ChannelSocket.processConnection(ChannelSocket.java:697)
at org.apache.jk.common.ChannelSocket$SocketConnection.runIt(ChannelSocket.java:889)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:684)
at java.lang.Thread.run(Thread.java:595)
1.可能是mysql的max connections设置的问题
2.可能是多次insert,update操作没有关闭session,需要在spring里配置transaction支持。
解决:
1.修改tomcat里的session 的time-out时间减少为20,(不是必改项)
2.对处理量大的对数据库insert或update的操作提供transaction支持.
=======================================
下面的是解决办法:
com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: Data source rejected establishment of connection, message from server: "Too many connections
因为你的mysql安装目录下的my.ini
解决方式:
打开MYSQL安装目录打开MY.INI找到max_connections(在大约第93行)默认是100 一般设置到500~1000比较合适,重启mysql,这样1040错误就解决啦。
max_connections=1000
在日常的MySQL服务器中,wait-timeout这个参数非常有用。
(在部分MySQL的默认配置中可能没有wait-timeout这个参数项,你在[mysqld]节中加上即可)
参数意义:
参数默认值:
这个参数的大概意思是某一个MySQL客户端连接闲置的最大时间值,即某一个MySQL客户端连接过程中,闲置的最大时间到达后服务器将其关闭。
MySQL服务器所支撑的最大连接数是有限的,因为每一个连接、第一个表打开的操作都要消耗服务器内存,理想状态是当一个MySQL客户端连接完成工作就自动断开释放内存,如果你的你的网站有大量的MySQL链接请求,这些连接完成SQL执行任务后空闲着啥事也不干,白白占用内存资源,如果 这些连接堆积起来,将导致MySQL超过最大连接数,从而无法新建MySQL连接,有可能导致“Too many connections”的错误。
可以在设置之前用show processlist查看一下MySQL状态,如果你发现你的MYSQL中有大量的Sleep进程,哪么你真的需要设置你的wait-timeout了。依你的程序而定设置多大的值 ,我的设置wait-timeout=10,MySQL中的所有Sleep线程最多只能“睡”10秒,之后就被强行关闭了。
本文转自http://seara520.blog.163.com/blog/static/16812769820107793713703/,所有权利归原作者所有。