<?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>cat brain.log &#124; less &#187; mysql</title>
	<atom:link href="http://log.largevoid.com/tag/mysql/feed/" rel="self" type="application/rss+xml" />
	<link>http://log.largevoid.com</link>
	<description>Getting it down on `paper`</description>
	<lastBuildDate>Mon, 06 Feb 2012 06:23:55 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Big MySQL Table? Watch the keyfile Length</title>
		<link>http://log.largevoid.com/2010/08/big-mysql-table-watch-the-keyfile-length/</link>
		<comments>http://log.largevoid.com/2010/08/big-mysql-table-watch-the-keyfile-length/#comments</comments>
		<pubDate>Tue, 03 Aug 2010 02:07:17 +0000</pubDate>
		<dc:creator>Paul</dc:creator>
				<category><![CDATA[Gotchas]]></category>
		<category><![CDATA[CHECK TABLE]]></category>
		<category><![CDATA[index]]></category>
		<category><![CDATA[MAX_ROWS]]></category>
		<category><![CDATA[myisamchk]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[REPAIR TABLE]]></category>
		<category><![CDATA[USE_FRM]]></category>

		<guid isPermaLink="false">http://log.largevoid.com/?p=417</guid>
		<description><![CDATA[I made some large tables (around 3-4 billion records each) and then tried to create indexes on one column in each of them. I found that MySQL stopped at a seemingly arbitrary maximum index file size (.MYI file) for both of them. When I tried to open either table, I received an error message &#8220;ERROR [...]]]></description>
			<content:encoded><![CDATA[<p>I made some large tables (around 3-4 billion records each) and then tried to create indexes on one column in each of them. I found that MySQL stopped at a seemingly arbitrary maximum index file size (.MYI file) for both of them. When I tried to open either table, I received an error message &#8220;ERROR 1016 (HY000): Can&#8217;t open file: &#8216;mytable.MYI&#8217; (errno: 144)&#8221; indicating that the index file was crashed.</p>
<p><code>CHECK TABLE mytable QUICK</code> reported &#8216;warning : Keyfile is almost full, 17179867136 of 17179867136 used&#8217; Then <code>myisamchk -dv mytable</code> reported similar information under &#8216;Max keyfile length,&#8221; and reported &#8220;Keyfile pointer (bytes): 3&#8242;</p>
<p>After a little digging around, I realized that a 3-byte keyfile pointer only allows the index file to hold 2^24 blocks (about 16 million blocks of 1024 bytes each). My index file was holding about 110 keys per block (e.g., each record needed 4 bytes for the key value, plus 4 bytes for the datafile pointer, and maybe one byte for null/housekeeping, and then each block kept a little more empty space). So the 3-byte keyfile pointer only allowed MySQL to index about 1.8 billion records. Then it gave up, leaving a corrupted index file.</p>
<p>I have found no documentation for how MySQL decides how big a keyfile pointer to use in the .MYI file. I had no trouble adding 3-4 billion records to the MYD file, so it didn&#8217;t occur to me that there would be a problem with the MAX_ROWS clause of the CREATE TABLE command (which I hadn&#8217;t specified). But that turned out to be the problem.</p>
<p>I recovered my data table without the index file, then issued <code>ALTER TABLE <mytable> MAX_ROWS=4000000000, ADD INDEX (mykey);</code> and now it looks like everything will be OK.</p>
<p>Here&#8217;s how I got my table back, without the index file (similar to what&#8217;s described above):</p>
<ol>
<li>make a backup of the data file (mytable.myd), just in case</li>
<li>create a new empty table with the same structure as the existing table, but no index keys.</li>
<li>copy the .FRM and .MYI files from the new (empty) table over the existing mytable.frm and mytable.myi files.</li>
<li>issue <code>REPAIR TABLE mytable USE_FRM;</code> It is very important to include the USE_FRM clause. That way, MySQL knows to make a new (empty) .MYI file that matches the .MYD file, rather than truncating the .MYD file to match the .MYI file. You will eventually get a message along the lines of &#8220;Number of rows changed from 0 to xxxx&#8221;.</li>
<li>Now you have a working table, with no indexes. Then you can set MAX_ROWS to something appropriate, and try again to make the indexes.</li>
</ol>
]]></content:encoded>
			<wfw:commentRss>http://log.largevoid.com/2010/08/big-mysql-table-watch-the-keyfile-length/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>MySQL config and iptables</title>
		<link>http://log.largevoid.com/2010/06/mysql-config-and-iptables/</link>
		<comments>http://log.largevoid.com/2010/06/mysql-config-and-iptables/#comments</comments>
		<pubDate>Sun, 13 Jun 2010 23:00:19 +0000</pubDate>
		<dc:creator>Paul</dc:creator>
				<category><![CDATA[Reference]]></category>
		<category><![CDATA[iptables]]></category>
		<category><![CDATA[mysql]]></category>

		<guid isPermaLink="false">http://log.largevoid.com/?p=348</guid>
		<description><![CDATA[This post is for reference. Of note, there is a good example of using iptables, and a description of how to bind your local mysql client to a remote mysql server. http://www.cyberciti.biz/tips/how-do-i-enable-remote-access-to-mysql-database-server.html]]></description>
			<content:encoded><![CDATA[<p>This post is for reference.  </p>
<p>Of note, there is a good example of using iptables, and a description of how to bind your local mysql client to a remote mysql server.</p>
<p>http://www.cyberciti.biz/tips/how-do-i-enable-remote-access-to-mysql-database-server.html</p>
]]></content:encoded>
			<wfw:commentRss>http://log.largevoid.com/2010/06/mysql-config-and-iptables/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Configuring MySQL</title>
		<link>http://log.largevoid.com/2009/11/configuring-mysql/</link>
		<comments>http://log.largevoid.com/2009/11/configuring-mysql/#comments</comments>
		<pubDate>Fri, 13 Nov 2009 00:11:20 +0000</pubDate>
		<dc:creator>Paul</dc:creator>
				<category><![CDATA[System Administration]]></category>
		<category><![CDATA[chkconfig]]></category>
		<category><![CDATA[configure]]></category>
		<category><![CDATA[init.d]]></category>
		<category><![CDATA[install]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[mysqld]]></category>

		<guid isPermaLink="false">http://log.largevoid.com/?p=108</guid>
		<description><![CDATA[The following is how I set up MySQL on wharf. First, ensure mysql is installed: ls /etc/init.d/my* Now, make mysql start on boot: sudo /sbin/chkconfig --level 35 mysqld on Start the mysql server: sudo /etc/init.d/mysqld start Make MySQL more secure: sudo /usr/bin/mysql_secure_installation Log into mysql as root: mysql -u root -p [to be entered by [...]]]></description>
			<content:encoded><![CDATA[<p>The following is how I set up MySQL on wharf.</p>
<ol>
<li>First, ensure mysql is installed: <code>ls /etc/init.d/my*</code></li>
<li>Now, make mysql start on boot: <code>sudo /sbin/chkconfig --level 35 mysqld on</code></li>
<li>Start the mysql server: <code>sudo /etc/init.d/mysqld start</code></li>
<li>Make MySQL more secure: <code>sudo /usr/bin/mysql_secure_installation</code></li>
<li>Log into mysql as root: <code>mysql -u root -p [to be entered by prompt]</code></li>
<li>Add another mysql user: <br/><code>mysql&gt; CREATE USER 'newuser'@'%' IDENTIFIED BY 'newuserpass';<br/>mysql&gt; GRANT SELECT,INSERT,UPDATE,DELETE,CREATE,DROP,ALTER ON *.* TO 'newuser'@'%';<br/>mysql&gt; FLUSH PRIVILEGES;</code></li>
<p></code></li>
<li>Exit mysql: <code>mysql&gt; exit</code></li>
<li>Test: <code>mysql -u &lt;newuser&gt; -p &lt;newuserpass&gt;</code></li>
</ol>
]]></content:encoded>
			<wfw:commentRss>http://log.largevoid.com/2009/11/configuring-mysql/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Things that Kill MySQL Performance</title>
		<link>http://log.largevoid.com/2009/11/things-that-kill-mysql-performance/</link>
		<comments>http://log.largevoid.com/2009/11/things-that-kill-mysql-performance/#comments</comments>
		<pubDate>Thu, 05 Nov 2009 01:59:19 +0000</pubDate>
		<dc:creator>Paul</dc:creator>
				<category><![CDATA[Lessons]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[optimize]]></category>
		<category><![CDATA[pdo]]></category>
		<category><![CDATA[performance]]></category>
		<category><![CDATA[sql]]></category>

		<guid isPermaLink="false">http://log.largevoid.com/?p=74</guid>
		<description><![CDATA[Failing to plan for scaling out, scaling up Not using EXPLAIN (learn from your mistakes) Using the wrong data types (hint: use smallest fixed-size) Using persistent connections in PHP (leads to zombie processes) Using a heavy DB abstraction layer (hint: use PDO or custom) Using the wrong storage engine (MEMORY, ARCHIVE, InnoDB, etc.) Using indexes [...]]]></description>
			<content:encoded><![CDATA[<ol>
<li>Failing to plan for scaling out, scaling up</li>
<li>Not using EXPLAIN (learn from your mistakes)</li>
<li>Using the wrong data types (hint: use smallest fixed-size)</li>
<li>Using persistent connections in PHP (leads to zombie processes)</li>
<li>Using a heavy DB abstraction layer (hint: use PDO or custom)</li>
<li>Using the wrong storage engine (MEMORY, ARCHIVE, InnoDB, etc.)</li>
<li>Using indexes improperly (hint: select in the order of the index; hint: keep primary key small)</li>
<li>Issuing SQL queries that can&#8217;t be cached easily; having too large of a query cache</li>
<li>Using stored procedures when prepared statements are better</li>
<li>Using functions on indexed columns in the WHERE clause</li>
<li>Not indexing important columns; having redundant indexes</li>
<li>Using sub-queries when joins would be better</li>
<li>Issuing avoidable deep scans</li>
<li>Doing SELECT COUNT(*) without WHERE on InnoDB table.</li>
<li>Failing to profile/benchmark your SQL</li>
<li>Not using AUTO_INCREMENT if applicable</li>
<li>Not using ON DUPLICATE KEY UPDATE (1 query vs 2)</li>
</ol>
<p>Reference:</p>
<ul>
<li><a href="http://www.slideshare.net/techdude/how-to-kill-mysql-performance">How to Kill MySQL Performance</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://log.largevoid.com/2009/11/things-that-kill-mysql-performance/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>MySQL DNS Caching</title>
		<link>http://log.largevoid.com/2008/12/mysql-dns-caching/</link>
		<comments>http://log.largevoid.com/2008/12/mysql-dns-caching/#comments</comments>
		<pubDate>Tue, 23 Dec 2008 11:09:29 +0000</pubDate>
		<dc:creator>Paul</dc:creator>
				<category><![CDATA[Lessons]]></category>
		<category><![CDATA[cache]]></category>
		<category><![CDATA[dns]]></category>
		<category><![CDATA[flush]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[sccoos]]></category>

		<guid isPermaLink="false">http://log.largevoid.com/?p=25</guid>
		<description><![CDATA[On December 12, 2008, SCCOOS metadata system was broken. The error was cryptic, but the message was clear: Connection to [IP] denied. Resolution Using the MySQL command-line tool: mysql -u admin -p [-h ] [-P ] mysql> flush hosts; That&#8217;s it! Chain of Events UCSD&#8217;s DNS was polluted, identifying 132.239.123.144 as ridge2000.org for the past [...]]]></description>
			<content:encoded><![CDATA[<p>On December 12, 2008, <a href="http://www.sccoos.org/meta/">SCCOOS metadata system</a> was broken.  The error was cryptic, but the message was clear: Connection to [IP] denied.</p>
<h3>Resolution</h3>
<p>Using the MySQL command-line tool:<br />
<code><br />
mysql -u admin -p [-h <hostname>] [-P
<port>]<br />
mysql> flush hosts;<br />
</code></p>
<p>That&#8217;s it!</p>
<h3>Chain of Events</h3>
<ul>
<li>UCSD&#8217;s DNS was polluted, identifying 132.239.123.144 as ridge2000.org for the past few weeks.</li>
<li>Sandbar was restarted last week, freeing up both the OS and MySQL DNS caches, which meant all new connections will need to query a DNS server to identify whether it&#8217;s an allowed machine or not (do you see a security vulnerability?).</li>
<li>Both the OS and MySQL cached the hostname, but MySQL further rejected all connections from alfredo because MySQL thought that alfredo was ridge2000 instead.</li>
<li>The <em>mysql</em> database, <em>user</em> table identifies user <em>sccoos</em> can connect to sandbar from <em>alfredo.ucsd.edu</em>.</li>
<li>The OS cache probably cleared, but since so few machines access sandbar, the MySQL cache hadn&#8217;t filled up yet.</li>
<li>Just last night (2008-12-22), the UCSD DNS purged the ridge2000.org name from its list, so UCSD&#8217;s DNS is clean, but any caches may still be polluted.</li>
</ul>
<ul>
<li>Windows machines cycle their caches regularly, so the problem isn&#8217;t more wide-spread or commonly understood.</li>
<li>The long-lasting MySQL DNS cache is disturbing, but alternatives would cripple the imperative nature of a database.</li>
</ul>
<h3>References</h3>
<ul>
<li><a href="http://dev.mysql.com/doc/refman/5.0/en/dns.html">MySQL DNS Reference</a></li>
<li><a href="http://en.wikipedia.org/wiki/Domain_Name_System">Domain Name System</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://log.largevoid.com/2008/12/mysql-dns-caching/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
<!-- This Quick Cache file was built for (  log.largevoid.com/tag/mysql/feed/ ) in 0.66031 seconds, on Feb 8th, 2012 at 4:16 am UTC. -->
<!-- This Quick Cache file will automatically expire ( and be re-built automatically ) on Feb 8th, 2012 at 5:16 am UTC -->
