Data source rejected establishment of connection, message from server: "Too many connections"
详细错误信息:
Caused by: 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:411)
at com.mysql.jdbc.Util.getInstance(Util.java:386)..............................
问题分析:
查看MySQL的当前最大连接数,登录MySQL:mysql -uroot -p,回车;输入密码,回车;
输入命令:select VARIABLE_VALUE from information_schema.GLOBAL_VARIABLES where VARIABLE_NAME='MAX_CONNECTIONS'; 回车
显示当前最大连接数为:151,之前通过文章“CentOS下mysql最大连接数设置 1040 too many connection”中的方法设置为3600了,现在怎么又变成151了?原来这个方法只是临时的修改了最大连接数,重新启动MySQL服务后就还原了。
解决问题:
要彻底解决问题还是要修改my.cnf配置文件,这里使用VI来修改,输入命令:vi /usr/my.cnf 回车;打开文件后按“i”键进入编辑状态;
在“[mysqld]”下面添加“max_connections=3600”,按Esc键进入命令模式,输入“:wq”回车(保存并退出)。
执行:service mysql restart 重新启动MySQL服务;启动服务的时间可能有点长,耐心等待……
注意:很多文章中提到在“[mysqld]”下面添加“set-variable=max_connections=1000”,根本不行,加了之后服务就启动不了了。
我这的环境是:CentOS 6.5 MySQL 5.6
错误原因:
太多的连接数,登录用户过多,配置的mysql连接数过小,或者某些连接没有关闭,导致连接数过大。
问题的解决:
修改mysql的my.ini配置文件,网上的说法:mysql安装目录下的my.ini中设定的并发连接数太少或者系统繁忙导致连接数被占满。
而项目实际上部署在linux系统上,需要找到my.cnf的配置文件,一般在etc/my.cnf,找到这个文件,添加如下行:
set-variable=max_connections=1000
set-variable=max_user_connections=500
set-variable=wait_timeout=200
之后重启mysql,生效。
net stop mysql
net start mysql
max_connections: 为设置最大的连接数
max_user_connections:设置每用户最大的 连接数500
wait_timeout:表示200秒后将关闭空闲连接,但对正在工作的连接不受影响。
//重新启动MySQL后使用下面的命令查看修改是否成功
# mysqladmin -uroot -p variables
Password:
//可以看到以下项说明修改成功
| max_connections | 1000
| max_user_connections | 500
| wait_timeout | 200
解决方法二:
还有一个可能就是代码里打开了太多的连接,但是忘记了在finally块里面关闭,从而导致在处理大数据的时候,抛出异常。下面这样的代码就不会有异常了。
try{
conn=Good.getConnection();
stmt = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE
, ResultSet.CONCUR_UPDATABLE);
String sql1="insert into cat_garbage values('"+rs.getInt("id")+"','"+rs.getInt("cid")+"','"+rs.getString("name")+"','"+rs.getString("keyword")+"')";
stmt.executeUpdate(sql1);
}
catch(SQLException|ClassNotFoundException|IOException e)
{
e.printStackTrace();
}
finally
{
if(stmt!= null)
stmt.close();
if(conn!= null)
conn.close();
}
要随时记住关闭rs,stmt,conn等资源,学会使用finally,在finally中,这些语句一定会执行
How to increase MySQL connections(max_connections)?
Q: Every socket of MySQL Database will have defaults connections as 100 but I am looking for any way to increase the number of possible connections > 100 to a socket connection of MySQL Database.??
A:
If you need to increase MySQL Connections without MySQL restart do like below
mysql> show variables like 'max_connections';
+-----------------+-------+
| Variable_name | Value |
+-----------------+-------+
| max_connections | 100 |
+-----------------+-------+
1 row in set (0.00 sec)
mysql> SET GLOBAL max_connections = 150;
Query OK, 0 rows affected (0.00 sec)
mysql> show variables like 'max_connections';
+-----------------+-------+
| Variable_name | Value |
+-----------------+-------+
| max_connections | 150 |
+-----------------+-------+
1 row in set (0.00 sec)
These settings will change at MySQL Restart.
For permanent changes add below line in my.cnf and restart MySQL
max_connections = 150
Data source rejected establishment of connection, message from server: "Too many connections"的更多相关文章
- Data source rejected establishment of connection, message from server: "Too many connections"解决办法
异常名称 //数据源拒绝从服务器建立连接.消息:"连接太多" com.MySQL.jdbc.exceptions.jdbc4.MySQLNonTransientConnection ...
- mysql: Data source rejected establishment of connection, message from server: "Too many connections"
http://www.oschina.net/question/558677_66703 com.mysql.jdbc.exceptions.MySQLNonTransientConnectionEx ...
- MySQLNonTransientConnectionException: Data source rejected establishment of connection, message from server: "Too many connections"
com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: Data source rejected establish ...
- com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: Data source rejected establishment of connection, message from server: "Too many connections"
报错: com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: Data source rejected estab ...
- Data source rejected establishment of connection, message from server: "Too many connections"
错误叙述性说明: 測试一段时间没有不论什么问题.今天突然用户无法登录,报错如Data source rejected establishment of connection, message fro ...
- 由于没有发现潜在的递归导致MySQL链接数溢出:MySQLNonTransientConnectionException: Data source rejected establishment of connection, message from server: "Too many connec
DAOProxy的代码:下面代码中红色高亮的就是出问题的地方,DAOFactory中会构造一个PersonDAOProxy,调用listPersons或者addPerson显然会导致递归,从而导致My ...
- 前段时间,接手一个项目使用的是原始的jdbc作为数据库的访问,发布到服务器上在运行了一段时间之后总是会出现无法访问的情况,登录到服务器,查看tomcat日志发现总是报如下的错误。 Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: Data source rejected est
前段时间,接手一个项目使用的是原始的jdbc作为数据库的访问,发布到服务器上在运行了一段时间之后总是会出现无法访问的情况,登录到服务器,查看tomcat日志发现总是报如下的错误. Caused by: ...
- Mysql:报错message from server: "Too many connections"(连接太多)
报错信息 Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: Data source re ...
- How to: Secure Connection Strings When Using Data Source Controls
https://docs.microsoft.com/en-us/previous-versions/dotnet/netframework-3.0/dx0f3cf2(v=vs.85) When wo ...
随机推荐
- 菜鸟教程之工具使用(四)——借助JRebel使Tomcat支持热部署
JRebel是一个J2EE热部署的工具.使用它可以减少浪费8-18%的开发时间在项目的构建和部署上.虽然Java也提供了HotSpot的JVM,但是如果你修改的类中有方法名称变动的话,HotSpot就 ...
- Stochastic Gradient Descent收敛判断及收敛速度的控制
要判断Stochastic Gradient Descent是否收敛,可以像Batch Gradient Descent一样打印出iteration的次数和Cost的函数关系图,然后判断曲线是否呈现下 ...
- 如何让 zend studio 10 识别 Phalcon语法并且进行语法提示
让 zend studio 10 识别 Phalcon语法并且进行语法提示 https://github.com/rogerthomas84/PhalconPHPDoc 下载解压后,把里面 phalc ...
- Python 操作redis有序集合(sorted set)
#coding:utf8 import redis r =redis.Redis(host=") 1.Zadd Zadd 命令用于将一个或多个成员元素及其分数值加入到有序集当中.如果某个成员 ...
- Is there a way to get a Cursor from a GreenDao Query object?
转:http://stackoverflow.com/questions/13584876/is-there-a-way-to-get-a-cursor-from-a-greendao-query-o ...
- JS实现获取当前URL和来源URL的方法
通用模式: Javascript 正常取来源网页的URL只要用: index.html: <!DOCTYPE html> <html lang="zh-cn"&g ...
- 【神经网络】LSTM 网络
Long Short Term 网络—— 一般就叫做 LSTM ——是一种 RNN 特殊的类型,可以学习长期依赖信息.LSTM 由Hochreiter & Schmidhuber (199 ...
- Oracle数据库密码过期
按照如下步骤进行操作:1.查看用户的proifle是哪个,一般是default: SQL>SELECT USERNAME,PROFILE FROM DBA_USERS; 2.查看指定概要文件(如 ...
- python.pandas read and write CSV file
#read and write csv of pandasimport pandas as pd goog =pd.read_csv(r'C:\python\demo\LiaoXueFeng\data ...
- myeclipse之SSH整合图文详解
首先搭建开发环境 打开MyEclipse,新建一个web project ,然后右击项目执行如下步骤: 开启服务器无错误即搭建成功,整合后项目目录: 另附上SSH所必须的开发包: