Reputation: 1971
I have several scripts which will run every 10 minutes . But sometimes the script will not executed properly so end up with a lot of sleep processes.
So I wish to restart mysql every n hours or when there are too many sleep processes , I tried something like
* * * * * /etc/init.d/mysql restart
(I know it's for every minute , but just an example) but not working.
Or is there any other way to prevent sleep processes?Each of my script might run for 8 minutes if there are many data.So i set up cron job for 10 minutes.
Thank you.
Upvotes: 0
Views: 2918
Reputation: 47321
Sleep processes are mysql connection in the idle status,
established and still waiting for next query to execute.
Chances are you are using myisam, and your script is doing some heavy write,
thus blocking table for read
However, you should NOT kill the processes in sleep.
The concern on sleep status is it still contribute to connection pool,
and might causing too many connections error
THINGS you have to do :
Here is an article about sleeping connection
Upvotes: 3
Reputation: 34877
First off, as stated by Bjoern above: this should be a temporary workaround as it's not so much of a solution.
Your problem is that you're trying to restart your mysql client, rather than the daemon (mysql d), try this instead:
0 * * * * /etc/init.d/mysqld restart
Upvotes: 4