Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I would like to repair + optimize my MySQL database once a week!

How could I do this?

share|improve this question
up vote 2 down vote accepted

mysqloptimize -A
mysqlrepair -A
I run these regularely, the -A option selects all databases

to run it regularely you would need a cronjob like this:

35 0 * * 1 mysqlrepair -A > /dev/null; mysqloptimize -A > /dev/null

This cronjob would run at 0:35 AM on every monday morning
If you need to authenticate, yould would use

mysqlrepair -uUSERNAME -pPASSWORD -A
mysqloptimize -uUSERNAME -pPASSWORD -A
share|improve this answer

For repair you can check auto-repair option. For optimization there is no recipe to do it automagicaly but you can try use script and see what it suggests you should tune.

share|improve this answer
Awesome, for some reason I was not familiar with mysqlcheck command. So a basic command is: mysqlcheck my_database --auto-repair – adrianTNT Oct 14 '15 at 13:41

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.