Aug
17
2010

Optimizing your MySQL Database

by   |  Posted in Tutorials  |  2 comments

I run my Web sites on a dedicated virtual server and every once in a while, I need to go in and optimize things to make sure everything runs smoothly. I am not an expert when it comes to shell commands, but do I know a few that really help keep things working the way they should.

One of the most important things I have come to realize is that you must keep an eye on your MySQL tables, because a problematic database can slow down your server dramatically. Databases that see a lot of queries often become fragmented and these are the databases that can start to cause you some problems. Luckily, there is a shell command that can go in and do all your de-fragmenting and optimizing for you.

I always make sure to back things up before I run this, just in case.

This command must be run from the shell and you need to be logged in as a root user:

mysqlcheck -u root -p --auto-repair --check --optimize --all-databases

Once the command has been entered, you will need to input your password. Then you will see it list through your database tables one by one as it works it magic.

You can read up on the mysqlcheck command to understand exactly what it does.

Another worthwhile tool is MySQLTuner. It can help you with recommendations on how to configure your MySQL to increase performance and stability. I use it every month too see if anything has been acting up and that is a good routine to get into to keep your sites running their best.

About the author:

A freelance web developer living in Montreal who spends most of his time writing for this site and building Premium themes for WordPress. You can find him on Twitter @bavotasan.

Site5 Affiliate Link
If you liked this, please share it.

Tags: ,

Short URL: http://bit.ly/9M4N36

Discussion 2 Comments

  1. Ely on August 19, 2010 at 8:03 pm

    I am wondering where to start from. Give me a step by step proceudure on how to do this from my cpanel. Great stuff tho

    • c.bavota on August 20, 2010 at 9:33 am

      This is something you have to do through SSH. If you are using a Mac, you can use Terminal. Not too sure what program works on a PC. You would first have to log in as the root user and then you can use the command above. If you are on a shared server, they usually don’t give you SSH access.