<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
<channel>
<title>Latest Articles by syberplex</title>
<link>http://www.articletrader.com/</link>
<description>Articles at ArticleTrader</description>
<language>en-us</language>
<item>
<title>Web Design: Automation of MySQL Optimization</title>
<link>http://www.articletrader.com/internet/web-design/web-design-automation-of-mysql-optimization.html</link>
<guid>http://www.articletrader.com/internet/web-design/web-design-automation-of-mysql-optimization.html</guid>
<pubDate>Wed, 23 Apr 2008 00:00:00 -0500</pubDate>
<description><![CDATA[ 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.<br /><br />Step 1: Create a PHP optimize script<br /><br />// Change vars as needed here<br /><br />$server = "localhost";<br /><br />$user = "mysql_user";<br /><br />$pwd = "mysql_password";<br /><br />$dbName = "mysql_dbName";<br /><br />$link = mysql_connect($server, $user, $pwd);<br /><br />if (!$link) {<br /><br />die('Could not connect: ' . mysql_error());<br /><br />}<br /><br />$db_selected = mysql_select_db($dbName, $link);<br /><br />if (!$db_selected) {<br /><br />die ('Can't use $dbName : ' . mysql_error());<br /><br />}<br /><br />// Find all tables in the selected DB<br /><br />$alltables = mysql_query("SHOW TABLES");<br /><br />// Process all tables.<br /><br />while ($table = mysql_fetch_assoc($alltables))<br /><br />{<br /><br />foreach ($table as $db => $tablename)<br /><br />{<br /><br />// Optimize them!<br /><br />mysql_query("OPTIMIZE TABLE '".$tablename."'")<br /><br />or die(mysql_error());<br /><br />}<br /><br />}<br /><br />mysql_close($link);<br /><br />?><br /><br />Step 2: Add this script into your daily cron jobs<br /><br />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!<br /><br />cd /etc/cron.daily<br /><br />echo '#!/bin/sh' > mysql_optimize; echo '/path/to/your/script.php' >> mysql_optimize; chmod 755 mysql_optimize;<br /><br />Now your all set! A quick and easy way to keep your high volume MySQL driven websites optimized!<br /><br />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).<br /><br />--<br />John Miller is a website designer at Syberplex Web Design operating out of Minnesota. Our <a href="http://www.syberplex.com">Minnesota Web Site Design</a> firm offers custom small business web site design, ecommerce, redesign services, and search engine optimization.<br><br>Source: <a href="http://www.articletrader.com/">http://www.articletrader.com</a> ]]></description>
</item>
</channel>
</rss>
