Too many sleeping processes (MySQL)

I have an issue in the peak hours where I get "error establishing a database connection”. In the logs, it’s “Too many connections”. I can’t connect to the DB manually without restarting mysql first.

I checked what is happening in the DB and it looks like that it’s mostly sleeping processes. I have no idea why.

On the server I run 10+ Wordpress sites with various themes&plugins (all through https://spinupwp.com/). What I did now is I ran MySQLTuner-perl and implemented its recommendations as MySQL was in the default settings. And I'm waiting for the peak hours which is not the smartest I think.

Can you recommend me a way how to identify which PHP file or http request is responsible for this?

mysql> show processlist;
+-------+-------+-----------+-----------------------+---------+------+----------+------------------+
| Id    | User  | Host      | db                    | Command | Time | State    | Info             |
+-------+-------+-----------+-----------------------+---------+------+----------+------------------+
|   423 | dbuser | localhost | NULL                  | Query   |    0 | starting | show processlist |
|   448 | dbuser | localhost | my_dbname_wp | Sleep   |  242 |          | NULL             |
|   452 | dbuser | localhost | my_dbname_wp | Sleep   |  242 |          | NULL             |
|   455 | dbuser | localhost | my_dbname_wp | Sleep   |  241 |          | NULL             |
|   936 | dbuser | localhost | my_dbname_wp | Sleep   |  217 |          | NULL             |
|  5715 | dbuser | localhost | my_dbname_wp | Sleep   |  164 |          | NULL             |
|  8669 | dbuser | localhost | my_dbname_wp | Sleep   |  139 |          | NULL             |
| 10353 | dbuser | localhost | my_dbname_wp | Sleep   |  125 |          | NULL             |
| 10631 | dbuser | localhost | my_dbname_wp | Sleep   |  123 |          | NULL             |
| 10724 | dbuser | localhost | my_dbname_wp | Sleep   |  122 |          | NULL             |
| 10867 | dbuser | localhost | my_dbname_wp | Sleep   |  121 |          | NULL             |
| 11084 | dbuser | localhost | my_dbname_wp | Sleep   |  119 |          | NULL             |
| 11102 | dbuser | localhost | my_dbname_wp | Sleep   |  119 |          | NULL             |
| 11226 | dbuser | localhost | my_dbname_wp | Sleep   |  118 |          | NULL             |
| 11669 | dbuser | localhost | my_dbname_wp | Sleep   |  114 |          | NULL             |
| 11726 | dbuser | localhost | my_dbname_wp | Sleep   |  114 |          | NULL             |
| 11851 | dbuser | localhost | my_dbname_wp | Sleep   |  113 |          | NULL             |
| 11994 | dbuser | localhost | my_dbname_wp | Sleep   |  112 |          | NULL             |
| 12006 | dbuser | localhost | my_dbname_wp | Sleep   |  112 |          | NULL   


Read more here: https://stackoverflow.com/questions/66386677/too-many-sleeping-processes-mysql

Content Attribution

This content was originally published by Tony MF at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: