简体   繁体   English

MySQL中的连接错误太多

[英]Too many connections error in mysql

I am developing an app using C# and MySql ( stored procedure ). 我正在使用C#和MySql( 存储过程 )开发一个应用程序 After running the app for certain time it shows Too many connection . 在运行该应用程序一段时间后,它显示连接过多 Then I used commands like SHOW STATUS WHERE variable_name = 'Threads_connected'; 然后,我使用了SHOW STATUS WHERE variable_name = 'Threads_connected';类的命令SHOW STATUS WHERE variable_name = 'Threads_connected'; and SHOW PROCESSLIST; SHOW PROCESSLIST; to debug the problem. 调试问题。 It seems each time I run any action on my app, mysql creates new thread and the thread is marked as Sleep . 似乎每次我对应用程序执行任何操作时,mysql都会创建一个新线程,并且该线程被标记为Sleep Moreover the thread does not close on time. 而且线程不会按时关闭。 I found one solution ie setting mysql environment variables as below. 我找到了一种解决方案,即如下设置mysql环境变量。

 interactive_timeout=180
 wait_timeout=180
  1. Is this solution have any impact on the app as it automatically kills the connection? 该解决方案会自动终止连接,对应用程序有影响吗? What happens if data fetching time from database is a bit long? 如果从数据库中获取数据的时间过长会怎样?
  2. I am expecting huge traffic about 1000 at a time. 我预计一次会有大约1000笔巨大的流量。 So what should be the max connection number in mysql? 那么,mysql中的最大连接数应该是多少? Will that degrade the mysql performance? 这会降低mysql的性能吗?

[Note: There is no problem in my app as I have closed every mysql connection] [注意:我的应用程序没有问题,因为我已经关闭了每个mysql连接]

Thanks in advance. 提前致谢。

I hope below artical will help you to get answer of your 2nd point 我希望下面的文章能帮助您获得第二点的答案

http://dev.mysql.com/doc/refman/5.5/en/too-many-connections.html http://dev.mysql.com/doc/refman/5.5/en/too-many-connections.html

In cases where an application doesn't close connections properly, wait_timeout is an important parameter to tune and discard unused or idle connections to minimize the number of active connections to your MySQL server – and this will ultimately help to avoid the “Too many connections” error. 如果应用程序无法正确关闭连接,wait_timeout是调整和丢弃未使用或空闲连接以最小化与MySQL服务器的活动连接数的重要参数,这最终将有助于避免“连接过多”错误。

Threads_running is a valuable metric to monitor as it doesn't count sleeping threads – it shows active and the amount of queries currently processing, while threads_connected status variables show all connected threads value including idle connections as well Threads_running是一个有价值的度量指标,因为它不计算休眠线程的数量–它显示活动线程和当前正在处理的查询数量,而threads_connected状态变量显示所有连接的线程值,包括空闲连接

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM