MySQL报Too many connections
错误信息
Exception in thread "main" java.sql.SQLNonTransientConnectionException: Data source rejected establishment of connection, message from server: "Too many connections" at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:110) at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:97) at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:122) at com.mysql.cj.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:835) at com.mysql.cj.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:455) at com.mysql.cj.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:240) at com.mysql.cj.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:199) at java.sql.DriverManager.getConnection(DriverManager.java:664) at java.sql.DriverManager.getConnection(DriverManager.java:247)
错误原因
mysql默认的连接为100个,如果连接数超过该值,则会报Too many connections
另外一个原因是没有及时关闭数据库连接
解决办法
1.使用数据库连接之后,一定要及时关闭数据库连接
2.如果确实需要一定数量的数据库连接,可修改配置文件修改数据库连接数量
修改/etc/my.cnf文件 [mysqld]新添加一行如下参数: max_connections=4096
相关推荐
Andrea0 2020-09-18
大黑牛 2020-08-15
ASoc 2020-11-14
Cherishyuu 2020-08-19
dongtiandeyu 2020-08-18
CoderYYN 2020-08-16
Dullonjiang 2020-08-11
gaozhennan 2020-08-03
mcvsyy 2020-08-02
zbcaicai 2020-07-29
AscaryBird 2020-07-27
liulin0 2020-07-26
ldcwang 2020-07-26
helloxusir 2020-07-25
娜娜 2020-07-20
pengpengflyjhp 2020-07-19
点滴技术生活 2020-07-19
人可 2020-07-18
chenjiazhu 2020-07-08