ArticleTrader.com
  

 Main Menu

  Home
  Member Login
  Forum
  Submit Article
  RSS Feeds
  Contact Us
  About

 Services

  Article Distribution
  Link Building

 Tools

  ArticleMS
  Directory Tracker

 Categories

  Automotive
  Business
  Computers
  Entertainment
  Finance
  Food
  Health
  Home and Family
  Internet
  » Affiliate Programs
  » Blogging
  » Domains
  » Email
  » Forums
  » Online Business
  » PPC Advertising
  » RSS
  » Security
  » SEO
  » Site Promotion
  » Spam
  » Web Design
  » Web Hosting
  Legal
  Science
  Self Improvement
  Shopping
  Society
  Sports
  Technology
  Travel
  Writing

89 users online.



 
  » Category Sponsors
  Communicating Your Needs

Home » Internet » Web-design » Web Design: Automation of MySQL Optimization
Article Stats:
74 Views
320 Words

Get Html Code
PDF | Print View | Post to your Site

Web Design: Automation of MySQL Optimization

Submitted by syberplex
Wed, 23 Apr 2008

In my quest to make our clients MySQL driven ecommerce websites running fast, I've pieced together a script and cron job that will save you some support calls down the road.

Step 1: Create a PHP optimize script

// Change vars as needed here

$server = "localhost";

$user = "mysql_user";

$pwd = "mysql_password";

$dbName = "mysql_dbName";

$link = mysql_connect($server, $user, $pwd);

if (!$link) {

die('Could not connect: ' . mysql_error());

}

$db_selected = mysql_select_db($dbName, $link);

if (!$db_selected) {

die ('Can't use $dbName : ' . mysql_error());

}

// Find all tables in the selected DB

$alltables = mysql_query("SHOW TABLES");

// Process all tables.

while ($table = mysql_fetch_assoc($alltables))

{

foreach ($table as $db => $tablename)

{

// Optimize them!

mysql_query("OPTIMIZE TABLE '".$tablename."'")

or die(mysql_error());

}

}

mysql_close($link);

?>

Step 2: Add this script into your daily cron jobs

Most popular Linux distros will have a /etc/cron.daily directory. Login as root and follow these steps to add your new website optimization script to your daily cron directory, thus never having to worry about manually optimizating again!

cd /etc/cron.daily

echo '#!/bin/sh' > mysql_optimize; echo '/path/to/your/script.php' >> mysql_optimize; chmod 755 mysql_optimize;

Now your all set! A quick and easy way to keep your high volume MySQL driven websites optimized!

We have found this script/cron to be very valuable with our high load web design projects that use large MySQL tables. It is most effective on tables that get updated a lot (with deletions and inserts).

About the Author

John Miller is a website designer at Syberplex Web Design operating out of Minnesota. Our Minnesota Web Site Design firm offers custom small business web site design, ecommerce, redesign services, and search engine optimization.


Source: ArticleTrader.com
Creative Commons License

Comments

No comments posted.

Add Comment

Your Name:


Your Email:


Comment

Enter the code shown

Visual CAPTCHA

 Top Authors

 1 alien82 (2756)
 2 stickystebee (2013)
 3 sverdlow (1712)
 4 juliet (1683)
 5 kajuba (1605)
 6 limalan88 (1557)
 7 AnthonyF (1244)
 8 isolvum (1019)
 9 IC (935)
 10 jkhbraveheart (847)
 11 artavia.seo (847)
 12 MarkeD (831)
 13 lets_j2top@ya.. (825)
 14 cj (784)
 15 cdmohatta (767)
  » Member List

 Latest Forum

» Article ID in url
» Categorymap, image and description
» The Search Function
» Adobe Photoshop CS4 Extended cheap order online
» Spam reporting tool?
» x Anne

 Distribution

Article Distribution

  
  Affiliate Program 2Checkout.com, Inc. is an authorized retailer of ArticleTrader.com

1.24s