Why do I have so many sleeping MySQL processes?
There are a bunch of MySQL processes in the Sleep state on my Linode. How can I fix that?
Seeing a lot of sleeping MySQL processes typically indicates an application is improperly using persistent connections to the database, or otherwise isn't disconnecting after it's finished. It's difficult to give specific guidance without knowing the specifics of your application, but I would start by reviewing its code/configuration to see if it's holding on to any database connections longer than it needs to.
If you can't do what @tommydavidson suggests because you don't have control of the guts of your app/service and/or it's configuration, you can lower the
I don't use MySQL personally but I've read that the MyISAM access method doesn't handle concurrent connections well. You could try InnoDB instead.
Hi, I have the same problem.
I thought it was the application's fault which is based on the symfony 5 framework.
So I stopped the apache service and restarted the mysql service, but the processes in the sleeping state remained the same (too many).
I set max_user_connections and max_connections to 5
and it doesn't work.
It seems that mysql starts many processes in sleeping state at startup.
How can I prevent it?
@runtime - This blog post from Percona has a few suggestions for why these sleeping processes are being created. Some common causes are timeout issues with your web server, long running queries, or multiple connections waiting for a query to complete. It's also possible that the applications querying MySQL just create lots of connections by default, as mentioned here. I specifically wanted to draw attention to this line: "unless your application is a very busy one, it's normal that not nearly every SQL process has something to do, so they sleep." Depending on how many sleeping processes you see, it could be normal and not performance-affecting. If there are thousands, though, you'll want to check your configurations and investigate further.