<?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>Binary Sludge &#187; MySQL</title>
	<atom:link href="http://www.binarysludge.com/category/mysql/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.binarysludge.com</link>
	<description>dredging the digital quagmire</description>
	<lastBuildDate>Sun, 22 Apr 2012 22:01:07 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>InnoDB disabled if ib_logfile files corrupted</title>
		<link>http://www.binarysludge.com/2012/02/09/innodb-disabled-if-ib_logfile-files-corrupted/</link>
		<comments>http://www.binarysludge.com/2012/02/09/innodb-disabled-if-ib_logfile-files-corrupted/#comments</comments>
		<pubDate>Thu, 09 Feb 2012 19:07:20 +0000</pubDate>
		<dc:creator>Andy</dc:creator>
				<category><![CDATA[MySQL]]></category>
		<category><![CDATA[RDS]]></category>
		<category><![CDATA[System Administration]]></category>
		<category><![CDATA[Troubleshooting]]></category>

		<guid isPermaLink="false">http://www.binarysludge.com/?p=810</guid>
		<description><![CDATA[<p><br /> I recently came across a dev VM running MySQL 5.0.77 (an old release, 28 January 2009) that didn&#8217;t have InnoDB available. skip-innodb wasn&#8217;t set, SHOW VARIABLES LIKE '%innodb%' looked as expected, but with one exception: the value of have-innodb was DISABLED.</p> <p>I confirmed this with SHOW ENGINES:</p> (root@localhost) [(none)]> show engines; +------------+----------+----------------------------------------------------------------+ &#124; [...]]]></description>
			<content:encoded><![CDATA[<p><img class="alignright mainimage" style="margin-top: 0; width: 25%;" title="InnoDB" src="http://c213.r13.cf3.rackcdn.com/InnoDB.gif" alt="InnoDB"><br />
I recently came across a dev VM running MySQL 5.0.77 (an <strong>old release</strong>, 28 January 2009) that didn&#8217;t have InnoDB available. <code>skip-innodb</code> wasn&#8217;t set, <code>SHOW VARIABLES LIKE '%innodb%'</code> looked as expected, but with one exception: the value of <code>have-innodb</code> was <code>DISABLED</code>.</p>
<p>I confirmed this with <code>SHOW ENGINES</code>:</p>
<pre>(root@localhost) [(none)]> show engines;
+------------+----------+----------------------------------------------------------------+
| Engine     | Support  | Comment                                                        |
+------------+----------+----------------------------------------------------------------+
| MyISAM     | DEFAULT  | Default engine as of MySQL 3.23 with great performance         |
| MEMORY     | YES      | Hash based, stored in memory, useful for temporary tables      |
| InnoDB     | DISABLED | Supports transactions, row-level locking, and foreign keys     |
...
</pre>
<p>(and chuckled to myself over the comment about MyISAM&#8217;s performance)</p>
<p><code>/var/log/mysqld.log</code> yielded the answer:</p>
<pre>
120127 17:17:51  mysqld started
120127 17:17:51 [Warning] /usr/libexec/mysqld: ignoring option '--engine-condition-pushdown' due to invalid value 'InnoDB'
InnoDB: Error: log file ./ib_logfile0 is of different size 0 20971520 bytes
InnoDB: than specified in the .cnf file 0 104857600 bytes!
120127 17:17:51 [Note] /usr/libexec/mysqld: ready for connections.
Version: '5.0.77-log'  socket: '/var/lib/mysql/mysql.sock'  port: 3306  Source distribution
</pre>
<p><code>innodb_file_per_table</code> was not set on this VM, and when the InnoDB log files had become corrupted and were not recognised, the engine couldn&#8217;t start. These <code>ib_logfile</code> files are <a href="http://www.pythian.com/news/1242/innodb-logfiles/">the crash recovery logs</a>:</p>
<blockquote><p>The unsung heroes of InnoDB are the logfiles. They are what makes InnoDB automatic crash recovery possible.</p>
<p>Database administrators of other DBMS may be familiar with the concept of a “redo” log. When data is changed, affected data pages are changed in the innodb_buffer_pool. Then, the change is written to the redo log, which in MySQL is the InnoDB logfile (ib_logfile0 and ib_logfile1). The pages are marked as “dirty”, and eventually get flushed and written to disk.</p>
<p>If MySQL crashes, there may be data that is changed that has not been written to disk. Those data pages were marked as “dirty” in the innodb_buffer_pool, but after a MySQL crash the innodb_buffer_pool no longer exists. However, they were written to the redo log. On crash recovery, MySQL can read the redo log (InnoDB log files) and apply any changes that were not written to disk.</p></blockquote>
<p><strong>edit:</strong> As pointed out by James Day <a href="http://www.binarysludge.com/2012/02/09/innodb-disabled-if-ib_logfile-files-corrupted/#comment-435540777">in the comments</a>, the original solution listed could cause further problems and so is only appropriate to a development/staging environment. When using production data he has an alternative suggestion:</p>
<blockquote><p>The correct solution to that error is to edit my.cnf/my.ini and set the size specified there to the size and number of log files on disk. InnoDB will then start normally.</p></blockquote>
<p>Thanks James!</p>
<p><br/>Of note: when this problem occurs, MySQL 5.0.77 erroneously returns this:</p>
<pre>
(root@some_host) [some_db]> SHOW ENGINE INNODB STATUS;
ERROR 1235 (42000): Cannot call SHOW INNODB STATUS because skip-innodb is defined
</pre>
<p><br/></p>
<p><strong>old solution for posterity:</strong></p>
<div style="color: lightgray;">The solution is to move the logs and allow InnoDB to recreate them. <strong>Don&#8217;t delete them</strong> &#8211; you may need them if your server has crashed or in case of data loss.</p>
<pre style="background: lightslategrey;">
/etc/init.d/mysql stop
mv /var/lib/mysql/ib_logfile0 /var/lib/mysql/ib_logfile0.bak
mv /var/lib/mysql/ib_logfile1 /var/lib/mysql/ib_logfile1.bak
/etc/init.d/mysql start
</pre>
<p>With the files absent, InnoDB recreates them and the engine is loaded successfully.
</p></div>
]]></content:encoded>
			<wfw:commentRss>http://www.binarysludge.com/2012/02/09/innodb-disabled-if-ib_logfile-files-corrupted/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Inode allocation on Amazon AWS RDS (Relation Database Service)</title>
		<link>http://www.binarysludge.com/2011/02/28/inode-allocation-on-amazon-aws-rds-relation-database-service/</link>
		<comments>http://www.binarysludge.com/2011/02/28/inode-allocation-on-amazon-aws-rds-relation-database-service/#comments</comments>
		<pubDate>Mon, 28 Feb 2011 19:00:21 +0000</pubDate>
		<dc:creator>Andy</dc:creator>
				<category><![CDATA[Amazon Web Services]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[RDS]]></category>
		<category><![CDATA[Troubleshooting]]></category>

		<guid isPermaLink="false">http://www.binarysludge.com/?p=404</guid>
		<description><![CDATA[<p></p> <p>The attached storage used by Amazon&#8217;s managed Relational Database Service has a known issue where the bytes per inode ratio is very high (default on RHEL5 systems is 4096, to be found in <a href="http://www.tin.org/bin/man.cgi?section=5&#38;topic=mke2fs.conf">/etc/mke2fs.conf</a>). Amazon does not allow any administrative access to these instances so there is no way to reformat the filesystem [...]]]></description>
			<content:encoded><![CDATA[<p><img width="200" height="200" alt="AWS Logo" src="http://c213.r13.cf3.rackcdn.com/AWS Logo.jpg" title="AWS Logo" style="margin-left: 0pt; margin-top: 0pt;" class="alignleft mainimage"></p>
<p>The attached storage used by Amazon&#8217;s managed Relational Database Service has a known issue where the bytes per inode ratio is very high (default on RHEL5 systems is 4096, to be found in <a href="http://www.tin.org/bin/man.cgi?section=5&amp;topic=mke2fs.conf">/etc/mke2fs.conf</a>). Amazon does not allow any administrative access to these instances so there is no way to reformat the filesystem to allocate more inodes, or attach storage the user can format with a different ratio.</p>
<p>This becomes problematic for databases that have many small tables (generally MyISAM tables, or InnoDB with the <code>innodb_file_per_table</code> setting) which quickly consume the available inodes. When the inode allocation is exhausted MySQL responds with</p>
<pre class="brush: plain; title: ; notranslate">&quot;ERROR 1030 (HY000): Got error 28 from storage engine&quot;</pre>
<p>The only current solution is to increase the size of attached storage, which increases the number of inodes (at the same fixed ratio). This is an expensive and inelegant fix; the RDS team are aware of the problem and working on a solution.</p>
<p>The difficulty of a solution in this context is RDS&#8217;s one-size-fits-all paradigm: many small tables are considered fringe usage and not accounted for, and allowing customers to set their own bytes to inode ratio will lead to wastefulness as admins over-estimate their total allocation.</p>
<p>My preferred solution would be to attach this metadata to an RDS instance (so it persists through disk resizing operations) but abstract it from the customer or only allow support to modify its value.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.binarysludge.com/2011/02/28/inode-allocation-on-amazon-aws-rds-relation-database-service/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>MySQL performance flow chart</title>
		<link>http://www.binarysludge.com/2011/01/03/mysql-performance-flow-chart/</link>
		<comments>http://www.binarysludge.com/2011/01/03/mysql-performance-flow-chart/#comments</comments>
		<pubDate>Mon, 03 Jan 2011 16:00:09 +0000</pubDate>
		<dc:creator>Andy</dc:creator>
				<category><![CDATA[MySQL]]></category>
		<category><![CDATA[Troubleshooting]]></category>

		<guid isPermaLink="false">http://www.binarysludge.com/?p=275</guid>
		<description><![CDATA[<p>Here&#8217;s an old-but-still-relevant (re)post from <a href="http://rackerhacker.com/2009/02/04/mysql-performance-flow-chart/">Major Hayen</a> on improving MySQL performance. It&#8217;s a neat, concise reference guide for MySQL emergencies!</p> <p style="text-align: center;"><a href="http://cdn.cloudfiles.mosso.com/c8031/improvingmysqlperformance.pdf"></a></p> <p><a href="http://rackerhacker.com/2009/02/04/mysql-performance-flow-chart/">Original post</a></p>]]></description>
			<content:encoded><![CDATA[<p>Here&#8217;s an old-but-still-relevant (re)post from <a href="http://rackerhacker.com/2009/02/04/mysql-performance-flow-chart/">Major Hayen</a> on improving MySQL performance. It&#8217;s a neat, concise reference guide for MySQL emergencies!</p>
<p style="text-align: center;"><a href="http://cdn.cloudfiles.mosso.com/c8031/improvingmysqlperformance.pdf"><img class="aligncenter" title="Improving MySQL Performance" src="http://cdn.cloudfiles.mosso.com/c8031/improvingmysqlperformance.jpg" alt="" width="306" height="240" /></a></p>
<p><a href="http://rackerhacker.com/2009/02/04/mysql-performance-flow-chart/">Original post</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.binarysludge.com/2011/01/03/mysql-performance-flow-chart/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>MySQL ERROR 1137 (HY000): Can&#8217;t reopen table: &#8216;tmp_journals&#8217;</title>
		<link>http://www.binarysludge.com/2010/03/18/mysql-error-1137-hy000-cant-reopen-table/</link>
		<comments>http://www.binarysludge.com/2010/03/18/mysql-error-1137-hy000-cant-reopen-table/#comments</comments>
		<pubDate>Thu, 18 Mar 2010 15:00:49 +0000</pubDate>
		<dc:creator>Andy</dc:creator>
				<category><![CDATA[MySQL]]></category>
		<category><![CDATA[error]]></category>
		<category><![CDATA[temporary table]]></category>

		<guid isPermaLink="false">http://www.binarysludge.com/?p=9</guid>
		<description><![CDATA[<p>When setting up a query using a temporary lookup table, I got this error:</p> <p class="note">It transpires that since 4.1 the way MySQL handles temporary tables has changed. This affects joins, unions and subqueries. There is an obvious fix:</p> <p class="note"> <p>Then the query is easy:</p> <p class="note">]]></description>
			<content:encoded><![CDATA[<p>When setting up a query using a temporary lookup table, I got this error:</p>
<pre class="brush: plain; title: ; notranslate">ERROR 1137 (HY000): Can't reopen table: 'tmp_journals'</pre>
<p class="note">It transpires that since 4.1 the way MySQL handles temporary tables has changed. This affects joins, unions and subqueries. There is an obvious fix:</p>
<p class="note">
<pre class="brush: sql; title: ; notranslate">mysql&gt; CREATE TEMPORARY TABLE tmp_journals_2 LIKE tmp_journals;
Query OK, 0 rows affected (0.00 sec)

mysql&gt; INSERT INTO tmp_journals_2 SELECT * FROM tmp_journals;
Query OK, 3228659 rows affected (2.01 sec)
Records: 3228659  Duplicates: 0  Warnings: 0 </pre>
<p>Then the query is easy:</p>
<pre class="brush: sql; title: ; notranslate">SELECT COUNT(1) cnt, journal_invoice_ref
FROM tmp_journals
GROUP BY journal_date
HAVING cnt &gt; 10000&lt;/pre&gt;

UNION

SELECT COUNT(1) cnt, journal_invoice_ref
FROM tmp_journals_2
GROUP BY journal_invoice_ref
HAVING cnt &lt; 10</pre>
<p class="note">
]]></content:encoded>
			<wfw:commentRss>http://www.binarysludge.com/2010/03/18/mysql-error-1137-hy000-cant-reopen-table/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

