Web Building - Web Site Development Tips
Thursday, 09 September 2010
Thursday, 09 September 2010 | Web Building - Web Site Development Tips
Go Daddy $7.49 .com domains 468x60
Home arrow Web Design arrow Web Design: Automation of MySQL Optimization
Main Menu
Home
Affiliate Programs
Blogs
Internet Service Providers
Link Building
RSS Feeds
Search Engines
SEO
Site Promotion
Web Design
Web Development
Web Domains
Web Hosting
Web Traffic
Articles
Links
Contact Us
TNX

Random SEO Articles
Web Design: Automation of MySQL Optimization
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 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
Read more at: http://www.articletrader.com/internet/web-design/web-design-automation-of-mysql-optimization.html.
 
< Prev   Next >
Go to top of page Go to top of page
 
Relevant Link Partners
Surrey Web Design
SEO specialists at WMG can analyse your website and make recommendations to improve the sites performance.
Graphic design agencies can improve the look of your website
Cheap Web Hosting
Cheap Web Hosting
Ventrilo Server
Guild Hosting
Search Engine Marketing
website building, web development
Web Submissions
Do you have a web building or web development article you'd like to submit to our website? If so, please send your web development article to This email address is being protected from spam bots, you need Javascript enabled to view it .
DreamTemplate - Web Templates
| Home | Affiliate Programs | Blogs | Internet Service Providers | Link Building | RSS Feeds | Search Engines | SEO | Site Promotion | Web Design | Web Development | Web Domains | Web Hosting | Web Traffic | Articles | Links | Contact Us |