5 thoughts on “Optimize MySQL tables for better performance

  1. Wouldn’t it be easier to use the mysql tools? e.g. mysqlcheck -o -A -uoptiuser

    • Hi Dylan,
      thanks for the suggestion. I’m sure that this is a great solution if you host your sites on a VPS or dedicated server.
      I’m using a shared hosting account for a few sites and the hosting company has disabled a lot of features (that’s why I wrote that function).
      I will try the mysqlcheck function using a CRON job.

  2. @Dylan,
    it works using the command line:
    mysqlcheck --optimize --all-databases --user=optiuser --password=somepassword

    But there is no check for tables with overhead ;). I think this is a great option for your own server (just run this command as a daily cron job).

  3. I like the script and find it very useful. I did make one change to the end of the script, where it sends or shows the message:


    This allows PHP to determine whether the script is being run from the command line or through the web server, and changes the destination of the messages accordingly.

Comments are closed.