<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>SoftLayer Blog &#187; MySQL</title>
	<atom:link href="http://blog.softlayer.com/tag/mysql/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.softlayer.com</link>
	<description>A Behind the Scenes Look at the Best Hosting Provider in the World</description>
	<lastBuildDate>Tue, 04 Jun 2013 20:27:40 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.4.1</generator>
		<item>
		<title>Using SoftLayer Object Storage to Back Up Your Server</title>
		<link>http://blog.softlayer.com/2012/using-softlayer-object-storage-to-back-up-your-server/</link>
		<comments>http://blog.softlayer.com/2012/using-softlayer-object-storage-to-back-up-your-server/#comments</comments>
		<pubDate>Thu, 27 Dec 2012 21:40:01 +0000</pubDate>
		<dc:creator>Ronald Steelman</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[SoftLayer]]></category>
		<category><![CDATA[Tips and Tricks]]></category>
		<category><![CDATA[Backups]]></category>
		<category><![CDATA[client]]></category>
		<category><![CDATA[coding]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[object storage]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[script]]></category>
		<category><![CDATA[SolusVM]]></category>
		<category><![CDATA[storage]]></category>
		<category><![CDATA[tips]]></category>

		<guid isPermaLink="false">http://blog.softlayer.com/?p=9795</guid>
		<description><![CDATA[Before I came to my senses and moved my personal servers to SoftLayer, I was one of many victims of a SolusVM exploit that resulted in the wide-scale attack of many nodes in my previous host&#8217;s Chicago data center. While I&#8217;m a firm believer in backing up my data, I could not have foreseen the [...]]]></description>
			<content:encoded><![CDATA[<p>Before I came to my senses and moved my personal servers to SoftLayer, I was one of many victims of a SolusVM exploit that resulted in the wide-scale attack of many nodes in my previous host&#8217;s Chicago data center. While I&#8217;m a firm believer in backing up my data, I could not have foreseen the situation I was faced with: Not only was my server in one data center compromised with all of its data deleted, but my backup server in one of the host&#8217;s other data centers was also attacked &#8230; This left me with old, stale backups on my local computer and not much else. I quickly relocated my data and decided that I should use <a href="http://www.softlayer.com/cloudlayer/storage/">SoftLayer Object Storage</a> to supplement and improve upon my backup and disaster recovery plans.</p>
<p>With <a href="https://github.com/softlayer/softlayer-object-storage-python">SoftLayer Object Storage Python Client</a> set up and the SoftLayer Object Storage Backup script &mdash; <a href="http://sldn.softlayer.com/blog/klandreth/Deglazing-slbackuppy-Usage-Object-Storage-Kitchen">slbackup.py</a> &mdash; in hand, I had the tools I needed to build a solid backup infrastructure easily. On Linux.org, I contributed an article about how to <a href="http://www.linux.org/article/view/mysql-backups-using-softlayer-object-storage">perform MySQL backups</a> with those resources, so the database piece is handled, but I also need to back up my web files, so I whipped up another quick <code>bash</code> script to run:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#!/bin/bash</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># The path the backups will be dumped to</span>
<span style="color: #007800;">DUMP_DIR</span>=<span style="color: #ff0000;">&quot;/home/backups/&quot;</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># Path to the web files to be backed up</span>
<span style="color: #007800;">BACKUP_PATH</span>=<span style="color: #ff0000;">&quot;/var/www/sites /&quot;</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># Back up folder name (mmddyyyy)</span>
<span style="color: #007800;">BACKUP_DIR</span>=<span style="color: #ff0000;">&quot;<span style="color: #780078;">`date +%m%d%Y`</span>&quot;</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># Backup File Name</span>
<span style="color: #007800;">DUMP_FILE</span>=<span style="color: #ff0000;">&quot;<span style="color: #780078;">`date +%m_%d_%Y_%H_%M_%S`</span>_site_files&quot;</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># SL container name</span>
<span style="color: #007800;">CONTAINER</span>=<span style="color: #ff0000;">&quot;site_backups&quot;</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># Create backup dir if doesn't exist</span>
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #000000; font-weight: bold;">!</span> <span style="color: #660033;">-d</span> <span style="color: #007800;">$DUMP_DIR</span><span style="color: #007800;">$BACKUP_DIR</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span>
        <span style="color: #c20cb9; font-weight: bold;">mkdir</span> <span style="color: #660033;">-p</span> <span style="color: #007800;">$DUMP_DIR</span><span style="color: #007800;">$BACKUP_DIR</span>
<span style="color: #000000; font-weight: bold;">fi</span>
&nbsp;
<span style="color: #c20cb9; font-weight: bold;">tar</span> <span style="color: #660033;">-zcvpf</span> <span style="color: #007800;">$DUMP_DIR</span><span style="color: #007800;">$BACKUP_DIR</span><span style="color: #000000; font-weight: bold;">/</span><span style="color: #007800;">$DUMP_FILE</span>.tar.gz <span style="color: #007800;">$BACKUP_PATH</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># Make sure the archive exists</span>
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #660033;">-f</span> <span style="color: #007800;">$DUMP_DIR</span><span style="color: #007800;">$BACKUP_DIR</span><span style="color: #000000; font-weight: bold;">/</span><span style="color: #007800;">$DUMP_FILE</span>.tar.gz <span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span>
        <span style="color: #000000; font-weight: bold;">/</span>root<span style="color: #000000; font-weight: bold;">/</span>slbackup.py <span style="color: #660033;">-s</span> <span style="color: #007800;">$DUMP_DIR</span><span style="color: #007800;">$BACKUP_DIR</span><span style="color: #000000; font-weight: bold;">/</span> <span style="color: #660033;">-o</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$CONTAINER</span>&quot;</span> <span style="color: #660033;">-r</span> <span style="color: #000000;">30</span>
&nbsp;
        <span style="color: #666666; font-style: italic;"># Remove the backup stored locally</span>
        <span style="color: #c20cb9; font-weight: bold;">rm</span> <span style="color: #660033;">-rf</span> <span style="color: #007800;">$DUMP_DIR</span><span style="color: #007800;">$BACKUP_DIR</span>
&nbsp;
        <span style="color: #666666; font-style: italic;"># Success</span>
        <span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #000000;">0</span>
<span style="color: #000000; font-weight: bold;">else</span>
        <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$DUMP_DIR</span><span style="color: #007800;">$BACKUP_DIR</span>/<span style="color: #007800;">$DUMP_FILE</span>.tar.gz does not exist.&quot;</span>
        <span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #000000;">1</span>
<span style="color: #000000; font-weight: bold;">fi</span></pre></div></div>

<p>It&#8217;s not the prettiest <code>bash</code> script, but it gets the job done. By tweaking a few variables, you can easily generate backups for any important directory of files and push them to your SoftLayer Object Storage account. If you want to change the retention time of your backups to be longer or shorter, you can change the <code>30</code> after the <code>–r</code> in the line below to the number of days you want to keep each backup:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">/</span>root<span style="color: #000000; font-weight: bold;">/</span>slbackup.py <span style="color: #660033;">-s</span> <span style="color: #007800;">$DUMP_DIR</span><span style="color: #007800;">$BACKUP_DIR</span><span style="color: #000000; font-weight: bold;">/</span> <span style="color: #660033;">-o</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$CONTAINER</span>&quot;</span> <span style="color: #660033;">-r</span> <span style="color: #000000;">30</span></pre></div></div>

<p>I created a script for each website on my server, and I set a CRON (crontab –e) entry to run each one on Sundays staggered by 5 minutes:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #000000;">5</span> <span style="color: #000000;">1</span> <span style="color: #000000; font-weight: bold;">*</span> <span style="color: #000000; font-weight: bold;">*</span> <span style="color: #000000;">0</span>  <span style="color: #000000; font-weight: bold;">/</span>root<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>cron<span style="color: #000000; font-weight: bold;">/</span>CRON-site1.com_web_files <span style="color: #000000; font-weight: bold;">&gt;</span> <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>null
<span style="color: #000000;">10</span> <span style="color: #000000;">1</span> <span style="color: #000000; font-weight: bold;">*</span> <span style="color: #000000; font-weight: bold;">*</span> <span style="color: #000000;">0</span>  <span style="color: #000000; font-weight: bold;">/</span>root<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>cron<span style="color: #000000; font-weight: bold;">/</span>CRON-site2.com_web_files <span style="color: #000000; font-weight: bold;">&gt;</span> <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>null
<span style="color: #000000;">15</span> <span style="color: #000000;">1</span> <span style="color: #000000; font-weight: bold;">*</span> <span style="color: #000000; font-weight: bold;">*</span> <span style="color: #000000;">0</span>  <span style="color: #000000; font-weight: bold;">/</span>root<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>cron<span style="color: #000000; font-weight: bold;">/</span>CRON-site3.com_web_files <span style="color: #000000; font-weight: bold;">&gt;</span> <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>null</pre></div></div>

<p>If you&#8217;re looking for an easy way to automate and solidify your backups, this little bit of code could make life easier on you. Had I taken the few minutes to put this script together prior to the attack I experienced at my previous host, I wouldn&#8217;t have lost any of my data. It&#8217;s easy to get lulled into &#8220;backup apathy&#8221; when you don&#8217;t <em>need</em> your backups, but just because nothing *has* happened to your data doesn&#8217;t mean nothing *can* happen to your data.</p>
<p>Take it from me &#8230; Be over-prepared and save yourself a lot of trouble.</p>
<p>-Ronald</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.softlayer.com/2012/using-softlayer-object-storage-to-back-up-your-server/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>ServerDensity: Tech Partner Spotlight</title>
		<link>http://blog.softlayer.com/2012/serverdensity-tech-partner-spotlight/</link>
		<comments>http://blog.softlayer.com/2012/serverdensity-tech-partner-spotlight/#comments</comments>
		<pubDate>Wed, 25 Jul 2012 14:20:22 +0000</pubDate>
		<dc:creator>Guest Blog</dc:creator>
				<category><![CDATA[Partner Marketplace]]></category>
		<category><![CDATA[Tips and Tricks]]></category>
		<category><![CDATA[Apache]]></category>
		<category><![CDATA[Infrastructure]]></category>
		<category><![CDATA[JIRA]]></category>
		<category><![CDATA[latency]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[partner]]></category>
		<category><![CDATA[partner marketplace]]></category>
		<category><![CDATA[prevention]]></category>
		<category><![CDATA[problems]]></category>
		<category><![CDATA[security]]></category>
		<category><![CDATA[server monitoring]]></category>
		<category><![CDATA[ServerDensity]]></category>
		<category><![CDATA[services]]></category>
		<category><![CDATA[space]]></category>
		<category><![CDATA[tips]]></category>
		<category><![CDATA[tracking]]></category>

		<guid isPermaLink="false">http://blog.softlayer.com/?p=8889</guid>
		<description><![CDATA[We invite each of our featured SoftLayer Tech Marketplace Partners to contribute a guest post to the SoftLayer Blog, and this week, we&#8217;re happy to welcome David Mytton, Founder of ServerDensity. Server Density is a hosted server and website monitoring service that alerts you when your website is slow, down or back up. Company Website: [...]]]></description>
			<content:encoded><![CDATA[<p class="attribution">We invite each of our featured SoftLayer Tech Marketplace Partners to contribute a guest post to the SoftLayer Blog, and this week, we&#8217;re happy to welcome David Mytton, Founder of <a href="http://www.serverdensity.com/">ServerDensity</a>. Server Density is a hosted server and website monitoring service that alerts you when your website is slow, down or back up.</p>
<div class="more-info"><strong>Company Website:</strong> <a href="http://www.serverdensity.com/">http://www.serverdensity.com/</a><br />
<strong>Tech Partners Marketplace:</strong> <a href="http://www.softlayer.com/partners/marketplace/serverdensity">http://www.softlayer.com/marketplace/serverdensity</a></div>
<style type="text/css" media="screen">
h4{
font-size:16px;
color: #972F2C;
margin-bottom:0;
padding-bottom:0;
}
</style>
<h3>5 Ways to Minimize Downtime During Summer Vacation </h3>
<p>It&#8217;s a fact of life that everything runs smoothly until you&#8217;re out of contact, away from the Internet or on holiday. However, you can&#8217;t be available 24/7 on the chance that something breaks; instead, there are several things you can do to ensure that when things go wrong, the problem can be managed and resolved quickly. To help you set up your own &#8220;get back up&#8221; plan, we&#8217;ve come up with a checklist of the top five things you can do to prepare for an ill-timed issue. </p>
<h4 style="margin-bottom:5px; padding-bottom:0;">1. Monitoring</h4>
<p style="margin-top:0; padding-top:0;">How will you know when things break? Using a tool like <a href="http://www.serverdensity.com/">Server Density</a> &mdash; which combines availability monitoring from locations around the world with internal server metrics like disk usage, Apache and MySQL &mdash; means that you can be alerted if your site goes down, and have the data to find out why.</p>
<p>Surprisingly, the most common problems we see are some that are the easiest to fix. One problem that happens all too often is when a customer simply runs out of disk space in a volume! If you&#8217;ve ever had it happen to you, you know that running out of space will break things in strange ways &mdash; whether it prevents the database from accepting writes or fails to store web sessions on disk. By doing something as simple as setting an alert to monitor used disk space for all important volumes (not just root) at around 75%, you&#8217;ll have proactive visibility into your server to avoid hitting volume capacity.</p>
<p>Additionally, you should define triggers for unusual values that will set off a red flag for you. For example, if your Apache requests per second suddenly drop significantly, that change could indicate a problem somewhere else in your infrastructure, and if you&#8217;re not monitoring those indirect triggers, you may not learn about those other problems as quickly as you&#8217;d like. Find measurable direct and indirect relationships that can give you this kind of early warning, and find a way to measure them and alert yourself when something changes.</p>
<h4 style="margin-bottom:5px; padding-bottom:0;">2. Dealing with Alerts</h4>
<p style="margin-top:0; padding-top:0;">It&#8217;s no good having alerts sent to someone who isn&#8217;t responding (or who can&#8217;t at a given time). Using a service like <a href="http://www.pagerduty.com">Pagerduty</a> allows you to define on-call rotations for different types of alerts. Nobody wants to be on-call every hour of every day, so differentiating and channeling alerts in an automated way could save you a lot of hassle. Another huge benefit of a platform like Pagerduty is that it also handles escalations: If the first contact in the path doesn&#8217;t wake up or is out of service, someone else gets notified quickly.</p>
<p><span id="more-8889"></span></p>
<h4 style="margin-bottom:5px; padding-bottom:0;">3. Tracking Incidents</h4>
<p style="margin-top:0; padding-top:0;">Whether you&#8217;re the only person responsible or you have a team of engineers, you&#8217;ll want to track the status of alerts/issues, particularly if they require escalation to different vendors. If an incident lasts a long time, you&#8217;ll want to be able to hand it off to another person in your organization with all of the information they need. By tracking incidents with detailed notes information, you can avoid fatigue and prevent unnecessary repetition of troubleshooting steps.</p>
<p>We use <a href="http://www.atlassian.com/software/jira/overview">JIRA</a> for this because it allows you to define workflows an issue can progress along as you work on it. It also includes easy access to custom fields (e.g. specifying a vendor ticket ID) and can be assigned to different people.</p>
<h4 style="margin-bottom:5px; padding-bottom:0;">4. Understanding What Happened</h4>
<p style="margin-top:0; padding-top:0;">After you have received an alert, acknowledged it and started tracking the incident, it&#8217;s time to start investigating. Often, this involves looking at logs, and if you only have one or two servers, it&#8217;s relatively easy, but as soon as you add more, the process can get exponentially more difficult.</p>
<p>We recommend piping them all into a log search tool like (<a href="http://www.softlayer.com/partners/marketplace/papertrail">fellow Tech Partners Marketplace participant</a>) <a href="http://www.papertrailapp.com">Papertrail</a> or <a href="http://www.loggly.com">Loggly</a>. Those platforms afford you access to all of your logs from a single interface with the ability to see incoming lines in real-time or the functionality to search back to when the incident began (since you&#8217;ve clearly monitored and tracked all of that information in the first three steps).</p>
<h4 style="margin-bottom:5px; padding-bottom:0;">5. Getting Access to Your Servers</h4>
<p style="margin-top:0; padding-top:0;">If you&#8217;re traveling internationally, access to the Internet via a free hotspot like the ones you find in Starbucks isn&#8217;t always possible. It&#8217;s always a great idea to order a portable 3G hotspot in advance of a trip. You can usually pick one up from the airport to get basic Internet access without paying ridiculous roaming charges. Once you have your connection, the next step is to make sure you can access your servers.</p>
<p>Both iPhone and Android have SSH and remote desktop apps available which allow you to quickly log into your servers to fix easy problems. Having those tools often saves a lot of time if you don&#8217;t have access to your laptop, but they also introduce a security concern: If you open server logins to the world so you can login from the dynamic IPs that change when you use mobile connectivity, then it&#8217;s worth considering a multi-factor authentication layer. We use <a href="http://www.duosecurity.com/">Duo Security</a> for several reasons, with one major differentiator being the modules they have available for all major server operating systems to lock down our logins even further.</p>
<p>You&#8217;re never going to escape the reality of system administration: If your server has a problem, you need to fix it. What you <em>can</em> get away from is the uncertainty of not having a clearly defined process for responding to issues when they arise.</p>
<p>-David Mytton, <a href="http://www.serverdensity.com/">ServerDensity</a></p>
<div class="tpm-note">This guest blog series highlights companies in SoftLayer&#8217;s <a href="http://www.softlayer.com/partners/marketplace/index">Technology Partners Marketplace</a>. <br/>These <a href="http://blog.softlayer.com/partner-marketplace/">Partners</a> have built their businesses on the SoftLayer Platform, and we&#8217;re excited for them to tell their stories. New Partners will be added to the Marketplace each month, so stay tuned for many more come.</div>
]]></content:encoded>
			<wfw:commentRss>http://blog.softlayer.com/2012/serverdensity-tech-partner-spotlight/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>MySQL Slow? Check for Fragmentation.</title>
		<link>http://blog.softlayer.com/2011/mysql-slow-check-for-fragmentation/</link>
		<comments>http://blog.softlayer.com/2011/mysql-slow-check-for-fragmentation/#comments</comments>
		<pubDate>Wed, 08 Jun 2011 13:30:21 +0000</pubDate>
		<dc:creator>Lee Thompson</dc:creator>
				<category><![CDATA[Customer Service]]></category>
		<category><![CDATA[SoftLayer]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[Tips and Tricks]]></category>
		<category><![CDATA[administrator]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[DBA]]></category>
		<category><![CDATA[fragmentation]]></category>
		<category><![CDATA[fragmented]]></category>
		<category><![CDATA[managed hosting]]></category>
		<category><![CDATA[managed services]]></category>
		<category><![CDATA[MySQL]]></category>

		<guid isPermaLink="false">http://blog.softlayer.com/2011/</guid>
		<description><![CDATA[Let&#8217;s say you have a website and you notice that any calls to your MySQL database take longer to render. If you don&#8217;t have a Database Administrator (DBA), this can be pretty frustrating. SoftLayer&#8217;s Managed Hosting line of business employs some of the best DBAs in the country and is one of the only managed [...]]]></description>
			<content:encoded><![CDATA[<p>Let&#8217;s say you have a website and you notice that any calls to your MySQL database take longer to render. If you don&#8217;t have a Database Administrator (DBA), this can be pretty frustrating. SoftLayer&#8217;s <a href="http://www.softlayer.com/managed-ps">Managed Hosting</a> line of business employs some of the best DBAs in the country and is one of the only managed hosting providers that offers MySQL and MsSQL DBA services, and I don&#8217;t just say that because I&#8217;m one of them &#8230; We&#8217;ve got the certifications to prove it. <img src='http://blog.softlayer.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<p>Given my area of expertise, I wanted to share a few some simple tips with you to help you tweak variables and improve the performance of your MySQL server. Given that every application is different, this isn&#8217;t necessarily a one-size-fits-all solution, but it&#8217;ll at least give you a starting point for troubleshooting.</p>
<p><strong>First: Get mysqltuner.pl.</strong> This is a fine script by Major Hayden that will give you some valuable information regarding the performance of your MySQL server. </p>
<p><strong>Second: Look for fragmented tables.</strong> What are fragmented tables? If there are random insertions into or deletions from the indexes of a table, the indexes may become fragmented. Fragmentation means that the physical ordering of the index pages on the disk is not close to the index ordering of the records on the pages or that there are many unused pages in the 64-page blocks that were allocated to the index. The symptoms of fragmented tables can be that table can take more disk space than needed or the results may return slower with more disk I/O than needed. <a href="http://www.innodb.com/">INNODB</a> users need to check the fragmentation often because when INNODB marks data as deleted, it never overwrites the blocks with new data &#8230; It just marks them as unusable. As a result, the data size is artificially inflated and data retrieval is slowed. </p>
<p>Fortunately, there is a way to see your table fragmentation and that is to run a query against the <code>information_schemea</code> to show all tables that are fragmented and the percentage of fragmentation:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">SELECT TABLE_SCHEMA, TABLE_NAME, CONCAT<span style="color: #7a0874; font-weight: bold;">&#40;</span>ROUND<span style="color: #7a0874; font-weight: bold;">&#40;</span>data_length <span style="color: #000000; font-weight: bold;">/</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span> <span style="color: #000000;">1024</span> <span style="color: #000000; font-weight: bold;">*</span> <span style="color: #000000;">1024</span> <span style="color: #7a0874; font-weight: bold;">&#41;</span>, <span style="color: #000000;">2</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>, <span style="color: #ff0000;">'MB'</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> DATA, CONCAT<span style="color: #7a0874; font-weight: bold;">&#40;</span>ROUND<span style="color: #7a0874; font-weight: bold;">&#40;</span>data_free  <span style="color: #000000; font-weight: bold;">/</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span> <span style="color: #000000;">1024</span> <span style="color: #000000; font-weight: bold;">*</span> <span style="color: #000000;">1024</span> <span style="color: #7a0874; font-weight: bold;">&#41;</span>, <span style="color: #000000;">2</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>, <span style="color: #ff0000;">'MB'</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>FREE from information_schema.TABLES where TABLE_SCHEMA NOT IN <span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #ff0000;">'information_schema'</span>,<span style="color: #ff0000;">'mysql'</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> and Data_free <span style="color: #000000; font-weight: bold;">&lt;</span> <span style="color: #000000;">0</span>;</pre></div></div>

<p>Fixing the fragmentation is easy, but there are a few caveats. When defragmenting a table, it will lock the table, so make sure you can afford the lock. To fix fragmented tables, you can simply run <code>optimize table &lt;table name&gt;;</code> to rebuild the table and all indexes or you can change the engine of the table with <code>alter table &lt;table name&gt; engine = INNODB;</code></p>
<p>I have written a simple bash script in bash to go through, defragment and optimize your tables:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#!/bin/bash</span>
&nbsp;
<span style="color: #007800;">MYSQL_LOGIN</span>=<span style="color: #ff0000;">'-u&lt;user name&gt; --password=&lt;passowrd&gt;'</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">for</span> db <span style="color: #000000; font-weight: bold;">in</span> $<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;SHOW DATABASES;&quot;</span> <span style="color: #000000; font-weight: bold;">|</span> mysql <span style="color: #007800;">$MYSQL_LOGIN</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">grep</span> <span style="color: #660033;">-v</span> <span style="color: #660033;">-e</span> <span style="color: #ff0000;">&quot;Database&quot;</span> <span style="color: #660033;">-e</span> <span style="color: #ff0000;">&quot;information_schema&quot;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
<span style="color: #000000; font-weight: bold;">do</span>
        <span style="color: #007800;">TABLES</span>=$<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;USE <span style="color: #007800;">$db</span>; SHOW TABLES;&quot;</span> <span style="color: #000000; font-weight: bold;">|</span> mysql <span style="color: #007800;">$MYSQL_LOGIN</span> <span style="color: #000000; font-weight: bold;">|</span>  <span style="color: #c20cb9; font-weight: bold;">grep</span> <span style="color: #660033;">-v</span> Tables_in_<span style="color: #7a0874; font-weight: bold;">&#41;</span>
        <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Switching to database <span style="color: #007800;">$db</span>&quot;</span>
        <span style="color: #000000; font-weight: bold;">for</span> table <span style="color: #000000; font-weight: bold;">in</span> <span style="color: #007800;">$TABLES</span>
        <span style="color: #000000; font-weight: bold;">do</span>
                <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #660033;">-n</span> <span style="color: #ff0000;">&quot; * Optimizing table <span style="color: #007800;">$table</span> ... &quot;</span>
                <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;USE <span style="color: #007800;">$db</span>; OPTIMIZE TABLE <span style="color: #007800;">$table</span>&quot;</span> <span style="color: #000000; font-weight: bold;">|</span> mysql <span style="color: #007800;">$MYSQL_LOGIN</span> <span style="color: #000000; font-weight: bold;">&gt;/</span>dev<span style="color: #000000; font-weight: bold;">/</span>null
                <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;done.&quot;</span>
        <span style="color: #000000; font-weight: bold;">done</span>
<span style="color: #000000; font-weight: bold;">done</span></pre></div></div>

<p>You&#8217;d be surprised how much of an impact table fragmentation has on MySQL performance, and this is an easy way to quickly troubleshoot your database that &#8220;isn&#8217;t as fast as it used to be.&#8221; If you follow the above steps and still can&#8217;t make sense of what&#8217;s causing your database to lag, our Managed Hosting team is always here to work with you to get your servers back in shape &#8230; And with the flexibility of month-to-month contract terms and the ability to add managed capabilities to specific pieces of your infrastructure, we have to earn your business every month with spectacular service.</p>
<p>-Lee</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.softlayer.com/2011/mysql-slow-check-for-fragmentation/feed/</wfw:commentRss>
		<slash:comments>12</slash:comments>
		</item>
	</channel>
</rss>
