MySQL異常刨析:ata source rejected establishment of connection, message from server: “Too many connection
異常現象
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)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:404)
at com.mysql.jdbc.Util.getInstance(Util.java:387)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:917)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:896)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:885)
at com.mysql.jdbc.MysqlIO.doHandshake(MysqlIO.java:1042)
at com.mysql.jdbc.ConnectionImpl.coreConnect(ConnectionImpl.java:2253)
at com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2284)
at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2083)
at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:806)
at com.mysql.jdbc.JDBC4Connection.<init>(JDBC4Connection.java:47)
at sun.reflect.GeneratedConstructorAccessor47.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:404)
at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:410)
at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:328)
at java.sql.DriverManager.getConnection(DriverManager.java:571)
at java.sql.DriverManager.getConnection(DriverManager.java:215)
at com.yuanhe.leasing.util.DBUtil.getConn(DBUtil.java:37)
at com.yuanhe.leasing.service.StatusListService.showManage(StatusListService.java:221)
at com.yuanhe.leasing.servlet.ListStatusServlet.doPost(ListStatusServlet.java:56)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:650)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:218)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:505)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:169)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:956)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:442)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1082)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:623)
at org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.doRun(AprEndpoint.java:2517)
at org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.run(AprEndpoint.java:2506)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:745)
原因分析:
1,未使用連線池,每次建立連結且沒有關閉
解決方法:
關閉連線,且依次關閉資料庫連線順序關閉!(RS,PS,CONN),確保異常時也要關閉。
finally{
try {
DBUtil.close(ps, conn, rs);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
原因2:連線數設定的太少
1.Mysql資料庫的預設連線數是100。
2.預設值100對於一般的程式都不是很夠用,如果只是在自己的電腦上除錯程式,有可能發現不了這個問題,因為除錯程式時會經常重起Tomcat。
3.如果使用Hibernate框架來進行資料庫操作,這個問題尤其明顯。
4.解決方法:加大Mysql連線數。在Mysql安裝檔案中,找到my.ini檔案,在裡面找到
max_connections=100,將這個100變大一點,直接來個1000
相關文章
- Too many files with unapproved license異常APP
- MySQL:Lost connection to MySQL server at 'readingMySqlServer
- Lost connection to MySQL server at 'reading authorization packet'MySqlServer
- Mysql host is blocked because of many connection errors;unblock解決方法MySqlBloCError
- java.net.ConnectException: Connection refused 異常JavaException
- SSL - SSLHandshakeException: Unrecognized SSL message, plaintext connection?ExceptionZedAI
- Mysql異常刨析:Could not commit JDBC transaction;No operations allowed after statement closedMySqlMITJDBC
- HttpClient遭遇Connection Reset異常,如何正確配置?HTTPclient
- Mysql mysql lost connection to server during query 問題解決方法MySqlServer
- MySQL ERROR 1040: Too many connectionsMySqlError
- Java中處理SocketException: Connection reset”異常的方法JavaException
- mysqldump: Error 2013: Lost connection to MySQL server during query when dumpingMySqlErrorServer
- 異常解決——GitLab : ssh: connect to host port 22: Connection refusedGitlab
- Linux啟動tomcat後執行shutdown.sh關閉時出現異常:Connection refused (Connection refused)LinuxTomcat
- ERROR 2013 (HY000): Lost connection to MySQL server at 'reading authorization paErrorMySqlServer
- [network][easy case]troubleshoting the connection to a remote serverREMServer
- MySQL報錯ERROR 2013 (HY000): Lost connection to MySQL server during queryMySqlErrorServer
- Check connection related issue of mysqlMySql
- nacos Connection refused (Connection refused)
- The API server is burning too much error budget 異常處理APIServerError
- Dr.Elephant mysql connection errorMySqlError
- Connection
- java.net.ConnectException: Connection refused (Connection refused)JavaException
- mysql備份提示 too many open files Errornumber 24MySqlError
- Establishing SSL connection without server's identity verification is not recommended.ServerIDE
- 【故障處理】ORA-28547: connection to server failed, probableServerAI
- Mysql 如何更改default collation_connection settingMySql
- MySQL問題處理——1040錯誤Too many connectionsMySql
- Error:Can't connect to SOCKS proxy:Connection refused (Connection refused)Error
- The connection to the server 10.10.0.2:6443 was refused - did you specify the right host or port?Server
- nmcli connection reload
- 解決 Too many symbol filesSymbol
- 684-Redundant Connection
- yarn socket connection timeoutYarn
- 關於Residual Connection
- Too many open files報錯處理
- Connection could not be established with host 求救
- TensorFlow Build from Source for macOSUIMac