How to optimize my Drupal database
Posted by Robert on 14 December 2009 05:31 AM
There are two easy ways to optimize the tables in your Drupal database.
The easiest way is to install the DB Maintenance module.
After the module is installed and activated, you can access it from your Drupal admin area > Administer > Site configuration > DB maintenance. Select the tables which you wish to optimize and click Optimize now.
The other, slightly more complicated way, is to create a php script with the sql query. The code you should include in the php file should be similar to this:
This will optimize the tables accesslog, cache, comments, node, users and watchdog. Feel free to add or remove tables from the query.
Once you have inserted the code, save the file. For the purposes of this example, we'll assume that the file is called optimize.php. Once the file is saved in your Drupal folder, you can execute it directly from a browser:
If you get a blank page without any errors, this means that the tables have been successfully optimized :)
You can also set a cron job in order to execute the optimization script at regular intervals. The cron job you set should be similar to this:
Make sure you don't set the cron to be executed too often. Once a week should be more than enough to keep your tables optimized :)