Irene Ling
Irene Ling

Reputation: 1971

Cron job for restart mysql if too many sleep processes

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

Answers (2)

ajreal
ajreal

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 :

  • find out the problem on your scripts, and make it work
  • or increase the maximum allow connection (palliatives, but work better than restart mysql server)

Here is an article about sleeping connection

Upvotes: 3

Oldskool
Oldskool

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

Related Questions