Code:
<?php $db = mysql_connect('localhost','user','password'); if(!$db) echo "cannot connect to the database"; mysql_select_db('user_drpl1'); $result=mysql_query('OPTIMIZE TABLE accesslog,cache,comments,node,users,watchdog;'); echo mysql_error(); ?>
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 folder, you can execute it directly from a browser:
404 - Not Found
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:
php /home/user/public_html/YOURLOGIN/optimize.php
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
here is other way doing it
i like using this way
each page you place your sql commands like
like index.php you place
Code:
@mysql_query("OPTIMIZE TABLE online") or die(mysql_error()); @mysql_query("OPTIMIZE TABLE user") or die(mysql_error()); @mysql_query("OPTIMIZE TABLE forums") or die(mysql_error()); @mysql_query("OPTIMIZE TABLE status") or die(mysql_error()); @mysql_query("OPTIMIZE TABLE download") or die(mysql_error()); @mysql_query("OPTIMIZE TABLE settings") or die(mysql_error());
Comment