欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

mysql "too many connections" 错误 之 mysql解决方法

程序员文章站 2023-11-24 08:49:10
解决方法是修改/etc/mysql/my.cnf,添加以下一行: set-variable = max_connections=500 或在启动命令中加上参数 max_co...
解决方法是修改/etc/mysql/my.cnf,添加以下一行:
set-variable = max_connections=500

或在启动命令中加上参数 max_connections=500
就是修改最大连接数,然后重启mysql.默认的连接数是100,太少了,所以容易出现如题错误.
以下是mysql.com网站的相关说明:
if you get a too many connections error when you try to connect to the mysqld server, this means that all available connections are in use by other clients.

the number of connections allowed is controlled by the max_connections system variable. its default value is 100. if you need to support more connections, you should restart mysqld with a larger value for this variable.

mysqld actually allows max_connections+1 clients to connect. the extra connection is reserved for use by accounts that have the super privilege. by granting the super privilege to administrators and not to normal users (who should not need it), an administrator can connect to the server and use show processlist to diagnose problems even if the maximum number of unprivileged clients are connected. see section 13.5.4.19, “show processlist syntax”.

the maximum number of connections mysql can support depends on the quality of the thread library on a given platform. linux or solaris should be able to support 500-1000 simultaneous connections, depending on how much ram you have and what your clients are doing. static linux binaries provided by mysql ab can support up to 4000 connections.

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才能生效

cmd->

net stop mysql

net start mysql

关于改变innodb_log_file_size后无法启动mysql的问题

innodb_buffer_pool_size=768m
innodb_log_file_size=256m
innodb_log_buffer_size=8m
innodb_additional_mem_pool_size=4m
innodb_flush_log_at_trx_commit=0
innodb_thread_concurrency=20
以上是对innodb引擎的初步优化, 发现是更新innodb_log_file_size=256m时候出现了问题,只要加上这个就无法启动,

后来才知道原来要stop服务先,然后再删除原来的文件………
打开/mysql server 5.5/data

删除ib_logfile0, ib_logfile1........ib_logfilen
再开启选项,成功启动