WordPress Database Optimization

WordPress is powered by PHP and depends on MySQL database; in fact, all the content, including the website settings, are stored in it. When your WordPress site is visited, the web server will query the database to retrieve all the necessary information to display. However, over time, the speed required for querying the database will increase due to the number of operations such as insert, updates, and  delete of data entries.

From time to time it is a good idea to do a little housekeeping with your WordPress installation.  MySQL databases don’t clean themselves, it will help to free up disk space and keep your database running smoothly.

As a start, try optimizing the overheads on your database as reported in phpMyAdmin. When this occurs, you need to run Optimize Table manually via WP Optimize plugin or phpMyAdmin

Warning: backup the WordPress database before making major optimization efforts

1. WP Optimize Plugin

If you’re not familiar with phpMyAdmin, then a WordPress plugin may be a safer option for you.  Those plugins will allow you to select the tables you wish to optimize and will also show you the total size of your database and how much of it can be reduced after you have completed the optimization.

WP-Optimize: This is a database cleanup and optimization tool.It does all of this without the use of phpMyAdmin (a program used to handle the administration of your MySQL servers). It will show you which tables are already optimized and the ones that need to be optimized. Select the option:  Optimize database tables. Then click the Process button below the option

WP Optimize plugin (click to see the screenshot)

2. phpMyAdmin
If you have access to phpMyAdmin, simply login to your phpMyAdmin and select the option 1: Check tables having overhead . Then at the side in the drop down box, select 2: Optimize Table,  this will take care of all of your tables at once.

Optimize tables with phpMyAdmin (click to see the screenshot)

Change MAMP MySQL password

MAMP creates a local server environment on Mac OS X by installing Apache, PHP and MySQL right out of the box.

The default username/password for MySQL install is root/root. That’s not safe. For security purposes, in our case we want sync between our WAMP and MAMP , it’s best to change that.

Open the Mac OS Terminal Application (located in “/Applications/Utilities”) and enter the following line

/Applications/MAMP/Library/bin/mysqladmin -u root -p password [NewPassword]

>> replace [NewPassword] with new password.
It will ask for the current password after you hit enter. Once you’ve entered that, the MySQL password is changed

Not over yet, open a text editor and change the password in the following files:


There’s the line that reads

$cfg['Servers'][$i]['password'] = 'root'

>> change the value ‘roor’ to the new password, retaining the quotes


There’s the line that reads

$link= @mysql_connect('/Applications/MAMP/tmp/mysql/mysql.sock','root','root'); ;

>> change the last parameter to the new password


>> replace the -proot with the new password.
Note: if we don’t change this one, we can have zombie mysqld’s running after you thought you stopped the server.