<?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>BlueGecko Denmark</title>
	<atom:link href="https://bluegecko.dk/author/mhamrick/feed/" rel="self" type="application/rss+xml" />
	<link>https://bluegecko.dk</link>
	<description>Your remote dba</description>
	<lastBuildDate>Fri, 22 Oct 2010 22:23:18 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.5.2</generator>
	<item>
		<title>InnoDB tablespace fragmentation (find it and fix it!)</title>
		<link>https://bluegecko.dk/innodb-tablespace-fragmentation-find-it-and-fix-it/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=innodb-tablespace-fragmentation-find-it-and-fix-it</link>
					<comments>https://bluegecko.dk/innodb-tablespace-fragmentation-find-it-and-fix-it/#comments</comments>
		
		<dc:creator><![CDATA[mhamrick]]></dc:creator>
		<pubDate>Fri, 22 Oct 2010 22:23:18 +0000</pubDate>
				<category><![CDATA[MySQL]]></category>
		<guid isPermaLink="false">http://www.bluegecko.net/?p=2229</guid>

					<description><![CDATA[If you frequently delete rows (or update rows with variable-length data types), you can end up with a lot of wasted space in your data file(s), similar to filesystem fragmentation. If you&#8217;re not using the innodb_file_per_table option, the only thing you can do about it is export and import the database, a time-and-disk-intensive procedure. But [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>If you frequently delete rows (or update rows with variable-length data types), you can end up with a lot of wasted space in your data file(s), similar to filesystem fragmentation.</p>
<p>If you&#8217;re not using the innodb_file_per_table option, the only thing you can do about it is export and import the database, a time-and-disk-intensive procedure.<span id="more-2229"></span></p>
<p>But if you are using innodb_file_per_table, you can identify and reclaim this space!</p>
<p>Prior to 5.1.21, the free space counter is available from the table_comment column of information_schema.tables. Here is some SQL to identify tables with at least 100M (actually 97.65M) of free space:</p>
<p><code>SELECT table_schema, table_name, table_comment FROM information_schema.tables WHERE engine LIKE 'InnoDB' AND table_comment RLIKE 'InnoDB free: ([0-9]{6,}).*';</code></p>
<p>Starting with 5.1.21, this was moved to the data_free column (a much more appropriate place):</p>
<p><code>SELECT table_schema, table_name, data_free/1024/1024 AS data_free_MB FROM information_schema.tables WHERE engine LIKE 'InnoDB' AND data_free &gt; 100*1024*1024;</code></p>
<p>You can reclaim the lost space by rebuilding the table. The best way to do this is using &#8216;alter table&#8217; without actually changing anything:</p>
<p><code>ALTER TABLE foo ENGINE=InnoDB;</code></p>
<p>This is what MySQL does behind the scenes if you run &#8216;optimize table&#8217; on an InnoDB table. It will result in a read lock, but not a full table lock. How long it takes is completely dependent on the amount of data in the table (but not the size of the data file). If you have a table with a high volume of deletes or updates, you may want to run this monthly, or even weekly.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://bluegecko.dk/innodb-tablespace-fragmentation-find-it-and-fix-it/feed/</wfw:commentRss>
			<slash:comments>5</slash:comments>
		
		
			</item>
		<item>
		<title>Recovering a Schema From InnoDB .frm Files</title>
		<link>https://bluegecko.dk/recovering-a-schema-from-innodb-frm-files/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=recovering-a-schema-from-innodb-frm-files</link>
					<comments>https://bluegecko.dk/recovering-a-schema-from-innodb-frm-files/#comments</comments>
		
		<dc:creator><![CDATA[mhamrick]]></dc:creator>
		<pubDate>Thu, 29 Apr 2010 16:21:49 +0000</pubDate>
				<category><![CDATA[MySQL]]></category>
		<category><![CDATA[Mike Hamrick]]></category>
		<guid isPermaLink="false">http://www.bluegecko.net/?p=1077</guid>

					<description><![CDATA[Sometimes you find yourself in a bad situation where your only hope of recovering your InnoDB data lies in a handful of .frm and .ibd data files that were heretofore part of a working MySQL installation. It could be the case that someone thought backing up InnoDB tables was simply a matter of of copying [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>Sometimes you find yourself in a bad situation where your only hope of recovering your InnoDB data lies in a handful of .frm and .ibd data files that were heretofore part of a working MySQL installation.  It could be the case that someone thought backing up InnoDB tables was simply a matter of  of copying the .ibd and .frm files somewhere safe. <span id="more-1077"></span>That mostly works for MyISAM files right?  Perhaps your system table space (ibdata1) became corrupted or was accidently deleted. Whatever the reason, you have a handful of .frm and .ibd files, and what you want is them imported into a functioning database.</p>
<p>The basics of how to do this are not too hard to understand, it&#8217;s the details that get tricky.  The first part of this problem is how to extract the table definition from the .frm files.  I&#8217;ll cover the second part of the problem in another post. You could write a program that reads and parses the .frm file and outputs the table definition, but that&#8217;s a lot of work &#8212; especially when you can trick MySQL into doing it for you.  Here is how you would do this for the file foo.frm.</p>
<p>[code type=&#8221;sql&#8221;] mysql&gt; CREATE TABLE `test`.`foo` (id int) ENGINE=InnoDB;<br />
[/code]</p>
<p>We&#8217;ve created an InnoDB table called foo.  MySQL has written a foo.frm and a foo.ibd file in $datadir/test.  It has also made a record of this table in the data dictionary.</p>
<p>[code type=&#8221;sql&#8221;]mysql&gt; FLUSH TABLES;<br />
[/code]</p>
<p>This causes MySQL to close all open tables and flush the query cache.  The idea is to force MySQL to forget about the table &#8220;foo` that we just created.</p>
<p>[code type=&#8221;bash&#8221;]bash# cp foo.frm /var/lib/mysql/test;<br />
[/code]</p>
<p>We just overwrote the table definition for test.foo.  We did it hot, while MySQL was still running.</p>
<p>[code type=&#8221;sql&#8221;]mysql&gt; SHOW CREATE TABLE `test`.`foo`;<br />
[/code]</p>
<p>That will output the table definition for the foo.frm file we just copied into the test directory.  MySQL will probably be a bit confused, as the information in the .frm file is not likely to match what is in the system table space.  You will probably see a message like this in your error log.</p>
<p><strong><em>[ERROR] Table ./test/foo has no primary key in InnoDB data dictionary, but has one in MySQL! If you created the table with a MySQL version &lt; 3.23.54 and did not define a primary key, but defined a unique key with all non-NULL columns, then MySQL internally treats that key as the primary key. You can fix this error by dump + DROP + CREATE + reimport of the table.</em></strong><em> </em></p>
<p>That&#8217;s OK though, we already got what we wanted, and now we can clean up.</p>
<p>[code type=&#8221;sql&#8221;]mysql&gt; DROP TABLE `test`.`foo`;<br />
[/code]</p>
<p>While this process works fine for a few tables, you can see how it&#8217;d be a real annoyance to have to go through this for a few hundered tables.  I wrote a script that automates this process for you, I call it <a title="recover_schema.pl" href="http://www.bluegecko.dk/recover_schema-pl" target="_self">recover_schema.pl</a>.  Here is how you use it:</p>
<p>[code type=&#8221;bash&#8221;]bash# recover_schema.pl &#8211;user=root &#8211;password=seekrit *.frm<br />
[/code]</p>
<p>This program needs to be run as root, and needs to have the credentials for a privileged MySQL user.  It will accept a number of .frm files to convert to CREATE TABLE statements on then command line.  It operates on the test database like the example above, and will create it if it does not exist.  One CREATE TABLE statement will be output for every .frm file passed in on the command line.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://bluegecko.dk/recovering-a-schema-from-innodb-frm-files/feed/</wfw:commentRss>
			<slash:comments>1</slash:comments>
		
		
			</item>
		<item>
		<title>Introducing the Bluegecko MySQL Training AMI</title>
		<link>https://bluegecko.dk/introducing-the-bluegecko-mysql-training-ami/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=introducing-the-bluegecko-mysql-training-ami</link>
					<comments>https://bluegecko.dk/introducing-the-bluegecko-mysql-training-ami/#respond</comments>
		
		<dc:creator><![CDATA[mhamrick]]></dc:creator>
		<pubDate>Wed, 21 Apr 2010 21:09:06 +0000</pubDate>
				<category><![CDATA[Amazon Web Services]]></category>
		<category><![CDATA[Education]]></category>
		<category><![CDATA[MySQL]]></category>
		<guid isPermaLink="false">http://www.bluegecko.net/?p=1022</guid>

					<description><![CDATA[I created the Bluegecko MySQL training AMI as a MySQL sandbox that folks could use to learn things about MySQL. I wanted the AMI to have MySQL 5.0, and a large collection of tools &#8212; for both tinkering and visualizing what is happening inside MySQL and on the system in general. I chose to host [...]


Related posts:<ol><li><a href="http://technocation.org/content/oursql-episode-41%3A-zmanda-%5Bbackup-series-%25236%5D" rel="bookmark" title="Permanent Link: OurSQL Episode 41:  Zmanda [backup series #6]">OurSQL Episode 41:  Zmanda [backup series #6]</a></li>
<li><a href="http://technocation.org/content/oursql-episode-38%3A-xtrabackup-(backup-series-%25235)" rel="bookmark" title="Permanent Link: OurSQL Episode 38: Xtrabackup (Backup Series #5)">OurSQL Episode 38: Xtrabackup (Backup Series #5)</a></li>
<li><a href="http://www.bluegecko.net/mysql/using-checksums-to-ensure-table-consistency-in-mysql/" rel="bookmark" title="Permanent Link: Using Checksums to Ensure Table Consistency in MySQL">Using Checksums to Ensure Table Consistency in MySQL</a></li>
</ol>]]></description>
										<content:encoded><![CDATA[<p>I created the Bluegecko MySQL training AMI as a MySQL sandbox that folks could use to learn things about MySQL.  I wanted the AMI to have MySQL 5.0, and a large collection of tools &#8212; for both tinkering and visualizing what is happening inside MySQL and on the system in general.</p>
<p>I chose to host the AMI on a <a href="http://aws.amazon.com/ec2/instance-types/">small instance</a> since they&#8217;re cheap to operate, which means you can fire up 3-4 of them to try out a replication scheme without feeling guilty.  It runs CentOS 5.4 and MySQL 5.0.77 from the CentOS repository.<span id="more-1022"></span></p>
<p>One of the goals I had for the training AMI was for it to be easy to visually inspect what is going on inside of MySQL and the system at large.  To that end I&#8217;ve installed <a href="http://www.cacti.net/">Cacti</a>, a graphing and visualization tool, and equipped it with templates that allow you to visualize <a href="http://www.markround.com/archives/48-Linux-iostat-monitoring-with-Cacti.html">i/o statistics</a> and <a href="http://code.google.com/p/mysql-cacti-templates/">detailed MySQL statistics</a>.  I&#8217;ve also installed a recent version of <a href="http://code.google.com/p/innotop/">Innotop</a> &#8212; a very handy top-like tool that lets you see a list of queries happening in real-time.  It&#8217;s also good for visualizing locking behavior.</p>
<p>Another goal I had for the AMI was that it&#8217;d be useful for learning how to backup/clone MySQL databases.  On startup I made certain that the ephemeral data store was converted into a physical volume, and then manged with the logical volume manager.  A 64GB logical volume is reserved for MySQL and is mounted in /var/lib/mysql.  I also installed <a href="http://www.percona.com/docs/wiki/percona-xtrabackup%3Astart">xtrabackup</a> 1.0 so one could experiment both with <a href="http://www.lenzg.net/mylvmbackup/">backups using LVM snapshots</a> as well as <a href="http://www.mysqlperformanceblog.com/2009/02/24/xtrabackup-open-source-alternative-for-innodb-hot-backup-call-for-ideas/">&#8216;hot&#8217; backups with xtrabackup</a>.</p>
<p>Naturally the AMI includes the <a href="http://code.google.com/p/maatkit/">Maatkit</a> tool suite, which I didn&#8217;t install from the CentOS repository because Maatkit changes so frequently &#8212; I wanted the most up-to-date and bug free version possible.  The <a href="http://www.maatkit.org/doc/mk-table-checksum.html">mk-table-checksum</a> and <a href="http://www.maatkit.org/doc/mk-table-sync.html">mk-table-sync</a> tools alone make it a valuable addition to any MySQL DBA&#8217;s toolkit.  In later blog posts we&#8217;ll examine using these tools to verify the consistency of replication slaves.</p>
<p>I also wanted to use the AMI for benchmarking various MySQL configurations as well as being able to simulate concurrent read/write load.  I built and installed <a href="http://www.mysqlperformanceblog.com/2006/08/18/sysbench-benchmark-tool/">sysbench 0.5 from SVN</a>. The various LUA scripts that drive sysbench&#8217;s MySQL testing behavior can be found in /root/sysbench.</p>
<p>Lastly, I wanted the AMI to be useful for learning about SQL, so I made sure some interesting sample datbases were available.  In the /root/datasets directory you&#8217;ll find SQL for the &#8216;<a href="http://dev.mysql.com/doc/world-setup/en/world-setup.html">world</a>&#8216;, &#8216;<a href="http://dev.mysql.com/doc/sakila/en/sakila.html">sakila</a>&#8216;, and &#8216;<a href="https://edge.launchpad.net/test-db">employee</a>&#8216; test databases.</p>
<p>The password for just about everything (system root, mysql root, cacti admin, etc) is &#8216;mysqltrain&#8217;.  If you want to see the Cacti graphs from your web browser you&#8217;ll want to open up port 80 on your EC2 Security Group to your home machine&#8217;s IP, the same goes for port 3306 if you want to use a local MySQL client such as SQLyog.</p>
<p>The AMI is named <a href="http://thecloudmarket.com/image/ami-9a8d65f3--">&#8220;Bluegecko/mysql-training.manifest.xml&#8221;</a>.  Enjoy!</p>
<p>Related posts:</p>
<ol>
<li><a href='http://technocation.org/content/oursql-episode-41%3A-zmanda-%5Bbackup-series-%25236%5D' rel='bookmark' title='Permanent Link: OurSQL Episode 41:  Zmanda [backup series #6]'>OurSQL Episode 41:  Zmanda [backup series #6]</a></li>
<li><a href='http://technocation.org/content/oursql-episode-38%3A-xtrabackup-(backup-series-%25235)' rel='bookmark' title='Permanent Link: OurSQL Episode 38: Xtrabackup (Backup Series #5)'>OurSQL Episode 38: Xtrabackup (Backup Series #5)</a></li>
<li><a href='http://www.bluegecko.dk/mysql/using-checksums-to-ensure-table-consistency-in-mysql/' rel='bookmark' title='Permanent Link: Using Checksums to Ensure Table Consistency in MySQL'>Using Checksums to Ensure Table Consistency in MySQL</a></li>
</ol>
]]></content:encoded>
					
					<wfw:commentRss>https://bluegecko.dk/introducing-the-bluegecko-mysql-training-ami/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Using Checksums to Ensure Table Consistency in MySQL</title>
		<link>https://bluegecko.dk/using-checksums-to-ensure-table-consistency-in-mysql/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=using-checksums-to-ensure-table-consistency-in-mysql</link>
					<comments>https://bluegecko.dk/using-checksums-to-ensure-table-consistency-in-mysql/#respond</comments>
		
		<dc:creator><![CDATA[mhamrick]]></dc:creator>
		<pubDate>Mon, 26 Jan 2009 17:17:12 +0000</pubDate>
				<category><![CDATA[MySQL]]></category>
		<category><![CDATA[checksum]]></category>
		<category><![CDATA[maakit]]></category>
		<category><![CDATA[percona]]></category>
		<category><![CDATA[table consistency]]></category>
		<guid isPermaLink="false">http://matthias.bluegecko.net/?p=422</guid>

					<description><![CDATA[If you&#8217;re using MySQL replication, chances are your master and slave databases aren&#8217;t entirely consistent. There are a number of reasons for this. Some MySQL functions like UUID() don&#8217;t replicate properly with statement based replication. Poor network connectivity can sometimes result in corrupted relay logs. Misconfigured software can accidently write to the slave database. Statements [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>If you&#8217;re using MySQL replication, chances are your master and slave databases aren&#8217;t entirely consistent.  There are a number of reasons for this.  Some MySQL functions like UUID() don&#8217;t replicate properly with statement based replication.  Poor network connectivity can sometimes result in corrupted relay logs.  Misconfigured software can accidently write to the slave database.  Statements on the master will sometimes complete partially due to MySQL shutdown or a statement getting killed or interrupted.  These are just a few reasons why replicated databases are often inconsistent with the master, and there are probably a lot more.  If you&#8217;re using a replicated MySQL slave for performing backups and you aren&#8217;t regularly verifying that your databases are consistent, you could be in for a nasty surprise when it comes time to restore from a backup.<span id="more-422"></span></p>
<p>This article explains how to perform these consistency checks both manually and with third party tools.  Maatkit is a collection of MySQL tools from the good folks at Percona.  The Maatkit tool we&#8217;ll be focusing on in the second half of this article is called mk-table-checksum.  This tool allows you to compare any number of replicated databases for consistency.</p>
<p>A checksum function reduces an arbitrary chunk of information (in this case table data) to a fixed sized number that represents this data.  This checksum acts as a fingerprint of sorts.  MySQL implements the CRC-32 checksum algorithm which can be used to reduce the string &#8216;hello world&#8217; to its 32-bit fingerprint.</p>
<p>[code language=&#8221;sql&#8221;] mysql&gt; SELECT CRC32(&#8216;hello world&#8217;);<br />
+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-+<br />
| CRC32(&#8216;hello world&#8217;) |<br />
+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-+<br />
|            222957957 |<br />
+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-+[/code]</p>
<p>You can also use the MySQL CHECKSUM TABLE command to perform a CRC-32 checksum on the every row in the table.</p>
<p>[code language=&#8221;sql&#8221;]<br />
mysql&gt; CREATE TABLE `foo` (`greeting` char(11)) ENGINE=MyISAM;<br />
mysql&gt; INSERT INTO `foo` VALUES (&#8216;hello world&#8217;);<br />
mysql&gt; CHECKSUM TABLE `foo`;<br />
+&#8212;&#8212;&#8212;&#8212;&#8212;+&#8212;&#8212;&#8212;&#8212;+<br />
| Table         | Checksum   |<br />
+&#8212;&#8212;&#8212;&#8212;&#8212;+&#8212;&#8212;&#8212;&#8212;+<br />
| bluegecko.foo | 3342502396 |<br />
+&#8212;&#8212;&#8212;&#8212;&#8212;+&#8212;&#8212;&#8212;&#8212;+<br />
[/code]</p>
<p>Now you&#8217;ll notice that this number is different from the &#8216;hello world&#8217; checksum we did saw earlier.  This is because CHECKSUM TABLE performs a CRC32 checksum on every row in the table including the row metadata. There is one or more bytes of metadata preceding each row.  I just happen to know that in this case there is one byte for this row and it will contain the number 253, or in hex 0xFD.</p>
<p>[code language=&#8221;sql&#8221;]mysql&gt; SELECT CRC32(CONCAT(0xFD, &#8216;hello world&#8217;));<br />
+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;+<br />
| CRC32(CONCAT(0xFD, &#8216;hello world&#8217;)) |<br />
+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;+<br />
|                         3342502396 |<br />
+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;+[/code]</p>
<p>The way data is organized in rows isn&#8217;t always consistent across major versions of MySQL, which means that the checksums returned by CHECKSUM TABLE for the same data on MySQL 4.1 and MySQL 5.0 may differ.  The checksums may also differ if you&#8217;re comparing two tables that have the same data but use different data types to store that data.</p>
<p>[code language=&#8221;sql&#8221;]<br />
mysql&gt; CREATE TABLE `bar` (`greeting` VARCHAR(255)) ENGINE=MyISAM;<br />
mysql&gt; INSERT INTO `bar` VALUES (&#8216;hello world&#8217;);<br />
mysql&gt; CHECKSUM TABLE `bar`;<br />
+&#8212;&#8212;&#8212;&#8212;&#8212;+&#8212;&#8212;&#8212;&#8212;+<br />
| Table         | Checksum   |<br />
+&#8212;&#8212;&#8212;&#8212;&#8212;+&#8212;&#8212;&#8212;&#8212;+<br />
| bluegecko.bar | 2963561228 |<br />
+&#8212;&#8212;&#8212;&#8212;&#8212;+&#8212;&#8212;&#8212;&#8212;+<br />
[/code]</p>
<p>As you can see, the checksum for bar doesn&#8217;t match the checksum for foo.  This is because the row metadata is different.  Variable length strings require extra record keeping in the metadata.</p>
<p>The above caveats not withstanding, you can see how CHECKSUM TABLE can be very handy to verify that a table on both the master and slave are identical. The simplest and most straightforward method of doing this involve logging in to both databases in separate windows and running the CHECKSUM TABLE command on the same table at roughly the same time.  This will likely work if the table you&#8217;re checksumming isn&#8217;t very busy.  But if the checksums differ, you&#8217;re going to need to use a slightly more complicated method.  On the master you start by locking the table so it can&#8217;t be written to:</p>
<p>[code language=&#8221;sql&#8221;]mysql&gt; LOCK TABLE `tablename` READ[/code]</p>
<p>Once you&#8217;ve done that, you run CHECKSUM TABLE on the master and note the checksum.  Then you go to the slave and use SHOW SLAVE STATUS to verify that it is caught up with the master and that all writes to the table have completed.  At this point you can run CHECKSUM TABLE on the slave and the two checksums should match.  As soon as you&#8217;ve done this you&#8217;ll want to run UNLOCK TABLES on the master so the table doesn&#8217;t remain locked.</p>
<p>You can see how doing this process manually for every table in your database could be time consuming and tedious work.  Wouldn&#8217;t it be great if there was a tool that could do this for you?  Luckily there is.  I&#8217;ll cover how to use mk-table-checksum in the next half of this article.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://bluegecko.dk/using-checksums-to-ensure-table-consistency-in-mysql/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>

<!--
Performance optimized by W3 Total Cache. Learn more: https://www.boldgrid.com/w3-total-cache/

Object Caching 23/103 objects using disk
Page Caching using disk: enhanced 

Served from: bluegecko.dk @ 2026-10-17 05:05:50 by W3 Total Cache
-->