---
title: "Optimise (optimize) MySQL databases"
date: "2009-01-01"
modified: "2013-03-03"
path: "/7-optimise-optimize-mysql-databases.html"
section: "/ramblings"
aliases:
  - "/7"
  - "/7-optimise-optimize-mysql-databases"
  - "/7.html"
  - "/ramblings/7-optimise-optimize-mysql-databases.html"
---

Here is a simple script for optimizing MySQL table. You will need to set the username and password for a user with "admin" like privileges.

<https://gist.github.com/1037581>

All it does it loop through each database and optimise the tables. I would suggest a simple weekly or monthly cron job to execute the script. The script though will e-mail the cron user a list of optimised databases - simply add ` >/dev/null 2>&1` to the end of the crontab line to send the data to nowhere.
