<?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>Jetpack Flight Log &#187; mysql</title>
	<atom:link href="http://jetpackweb.com/blog/topics/mysql/feed/" rel="self" type="application/rss+xml" />
	<link>http://jetpackweb.com/blog</link>
	<description>Rock{et}ing the interweb</description>
	<lastBuildDate>Wed, 19 May 2010 22:21:53 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Unobtrusive viewing of MySQL queries with tcpdump</title>
		<link>http://jetpackweb.com/blog/2009/09/16/unobstrusive-viewing-of-mysql-queries-with-tcpdump/</link>
		<comments>http://jetpackweb.com/blog/2009/09/16/unobstrusive-viewing-of-mysql-queries-with-tcpdump/#comments</comments>
		<pubDate>Wed, 16 Sep 2009 17:33:32 +0000</pubDate>
		<dc:creator>Brian Racer</dc:creator>
				<category><![CDATA[linux]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[sysadmin]]></category>
		<category><![CDATA[tcpdump]]></category>

		<guid isPermaLink="false">http://jetpackweb.com/blog/?p=381</guid>
		<description><![CDATA[There are times when you need to monitor the queries coming in to MySQL, but turning on query logging would create too much of a disk I/O hit, or you can&#8217;t restart the server to setup MySQL Proxy. Instead we can just monitor the network traffic and extract data that might be interesting using tcpdump [...]]]></description>
			<content:encoded><![CDATA[<p>There are times when you need to monitor the queries coming in to MySQL, but turning on query logging would create too much of a disk I/O hit, or you can&#8217;t restart the server to setup <a href="http://forge.mysql.com/wiki/MySQL_Proxy" target="_blank">MySQL Proxy</a>. Instead we can just monitor the network traffic and extract data that might be interesting using <strong>tcpdump</strong> and an inline perl script:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family: Monaco, monospace;"><span class="kw2">sudo</span> tcpdump <span class="re5">-i</span> lo <span class="re5">-s</span> <span class="nu0">0</span> <span class="re5">-l</span> <span class="re5">-w</span> - dst port <span class="nu0">3306</span> <span class="sy0">|</span> <span class="kw2">strings</span> <span class="sy0">|</span> <span class="kw2">perl</span> <span class="re5">-e</span> <span class="st_h">'
while(&lt;&gt;) { chomp; next if /^[^ ]+[ ]*$/;
  if(/^(SELECT|UPDATE|DELETE|INSERT|SET|COMMIT|ROLLBACK|CREATE|DROP|ALTER)/i) {
    if (defined $q) { print &quot;$q\n&quot;; }
    $q=$_;
  } else {
    $_ =~ s/^[ \t]+//; $q.=&quot; $_&quot;;
  }
}'</span></pre></div></div>

<p>This will only work for clients communicating via TCP &#8211; if you are connecting through &#8216;localhost&#8217; you will be going through a unix socket instead. If you switch &#8216;localhost&#8217; to &#8217;127.0.0.1&#8242; then your queries will go through the network stack.</p>
<p>If you just want to dump the traffic to a file for a little bit and analyze it later, do this instead:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family: Monaco, monospace;"><span class="kw2">sudo</span> tcpdump <span class="re5">-i</span> lo port <span class="nu0">3306</span> <span class="re5">-s</span> <span class="nu0">65535</span> <span class="re5">-x</span> <span class="re5">-n</span> <span class="re5">-q</span> -tttt<span class="sy0">&gt;</span> tcpdump.out</pre></div></div>

<p>You can then use <strong>mk-query-digest</strong> from <a href="http://www.maatkit.org/" target="_blank">Maatkit</a> with<strong>&#8211;type=tcpdump</strong>. See more about this at the <a href="http://www.mysqlperformanceblog.com/2009/07/01/gathering-queries-from-a-server-with-maatkit-and-tcpdump/" target="_blank">MySQL Performance Blog</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://jetpackweb.com/blog/2009/09/16/unobstrusive-viewing-of-mysql-queries-with-tcpdump/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Installing MySQL Ruby Gem on CentOS 5 (and an explanation about getopt&#8217;s double hyphens)</title>
		<link>http://jetpackweb.com/blog/2009/09/13/installing-mysql-ruby-gem-on-centos-5-and-an-explanation-about-getopt-double-hyphens/</link>
		<comments>http://jetpackweb.com/blog/2009/09/13/installing-mysql-ruby-gem-on-centos-5-and-an-explanation-about-getopt-double-hyphens/#comments</comments>
		<pubDate>Sun, 13 Sep 2009 22:37:23 +0000</pubDate>
		<dc:creator>Brian Racer</dc:creator>
				<category><![CDATA[mysql]]></category>
		<category><![CDATA[ruby]]></category>

		<guid isPermaLink="false">http://jetpackweb.com/blog/?p=62</guid>
		<description><![CDATA[I had an issue trying to build the mysql gem on CentOS 5.x. ERROR: While executing gem … &#40;Gem::Installer::ExtensionBuildError&#41; ERROR: Failed to build gem native extension. &#160; ruby extconf.rb update checking for mysql_query&#40;&#41; in -lmysqlclient… no ... After much hairpulling, two hyphens solved my problem: sudo gem install mysql -- \ --with-mysql-include=/usr/include/mysql \ --with-mysql-lib=/usr/lib/mysql A [...]]]></description>
			<content:encoded><![CDATA[<p>I had an issue trying to build the mysql gem on CentOS 5.x.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family: Monaco, monospace;">ERROR: While executing gem … <span class="br0">&#40;</span>Gem::Installer::ExtensionBuildError<span class="br0">&#41;</span>
ERROR: Failed to build gem native extension.
&nbsp;
ruby extconf.rb update
checking <span class="kw1">for</span> mysql_query<span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="kw1">in</span> -lmysqlclient… no
...</pre></div></div>

<p>After much hairpulling, two hyphens solved my problem:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family: Monaco, monospace;"><span class="kw2">sudo</span> gem <span class="kw2">install</span> mysql <span class="re5">--</span> \
<span class="re5">--with-mysql-include</span>=<span class="sy0">/</span>usr<span class="sy0">/</span>include<span class="sy0">/</span>mysql \
<span class="re5">--with-mysql-lib</span>=<span class="sy0">/</span>usr<span class="sy0">/</span>lib<span class="sy0">/</span>mysql</pre></div></div>

<p>A blog comment I found explains the double hyphens:</p>
<blockquote><p>
The double hyphens (–) tells the option parser that there is no more options on the command line. This special syntax comes from GNU getopt. Everything after ‘–’ is treated as non-options. This is useful if you want to write something on the command line that looks like an option but is not, or if it should be parsed though as an option to another program called by the one you are calling.</p>
<p>The two hyphens in this particular command string is important since the gem binary must not confuse the ‘–with-mysql-dir’ option as an option for gem it self. Instead this option should be passed on to the make command called in the gem internals.</p>
<p><a href="http://justaddwater.dk/">Thomas Watson</a>
</p></blockquote>
<p>And if you are on a 64-bit system, be sure to use <b>–-with-mysql-lib=/usr/lib64/mysql</b> instead.</p>
]]></content:encoded>
			<wfw:commentRss>http://jetpackweb.com/blog/2009/09/13/installing-mysql-ruby-gem-on-centos-5-and-an-explanation-about-getopt-double-hyphens/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Bash script to create MySQL database and user</title>
		<link>http://jetpackweb.com/blog/2009/07/20/bash-script-to-create-mysql-database-and-user/</link>
		<comments>http://jetpackweb.com/blog/2009/07/20/bash-script-to-create-mysql-database-and-user/#comments</comments>
		<pubDate>Tue, 21 Jul 2009 01:49:17 +0000</pubDate>
		<dc:creator>Brian Racer</dc:creator>
				<category><![CDATA[mysql]]></category>

		<guid isPermaLink="false">http://jetpackweb.com/blog/?p=170</guid>
		<description><![CDATA[Here is a little script I made to quickly and easily create users and databases for MySQL. I only use this for development, for actual deployed applications you would probably want to be more specific about the privileges given: #!/bin/bash &#160; EXPECTED_ARGS=3 E_BADARGS=65 MYSQL=`which mysql` &#160; Q1=&#34;CREATE DATABASE IF NOT EXISTS $1;&#34; Q2=&#34;GRANT ALL ON [...]]]></description>
			<content:encoded><![CDATA[<p>Here is a little script I made to quickly and easily create users and databases for MySQL. I only use this for development, for actual deployed applications you would probably want to be more specific about the privileges given:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family: Monaco, monospace;"><span class="co0">#!/bin/bash</span>
&nbsp;
<span class="re2">EXPECTED_ARGS</span>=<span class="nu0">3</span>
<span class="re2">E_BADARGS</span>=<span class="nu0">65</span>
<span class="re2">MYSQL</span>=<span class="sy0">`</span><span class="kw2">which</span> mysql<span class="sy0">`</span>
&nbsp;
<span class="re2">Q1</span>=<span class="st0">&quot;CREATE DATABASE IF NOT EXISTS $1;&quot;</span>
<span class="re2">Q2</span>=<span class="st0">&quot;GRANT ALL ON *.* TO '$2'@'localhost' IDENTIFIED BY '$3';&quot;</span>
<span class="re2">Q3</span>=<span class="st0">&quot;FLUSH PRIVILEGES;&quot;</span>
<span class="re2">SQL</span>=<span class="st0">&quot;<span class="es3">${Q1}</span><span class="es3">${Q2}</span><span class="es3">${Q3}</span>&quot;</span>
&nbsp;
<span class="kw1">if</span> <span class="br0">&#91;</span> <span class="re4">$#</span> <span class="re5">-ne</span> <span class="re1">$EXPECTED_ARGS</span> <span class="br0">&#93;</span>
<span class="kw1">then</span>
  <span class="kw3">echo</span> <span class="st0">&quot;Usage: $0 dbname dbuser dbpass&quot;</span>
  <span class="kw3">exit</span> <span class="re1">$E_BADARGS</span>
<span class="kw1">fi</span>
&nbsp;
<span class="re1">$MYSQL</span> <span class="re5">-uroot</span> <span class="re5">-p</span> <span class="re5">-e</span> <span class="st0">&quot;<span class="es2">$SQL</span>&quot;</span></pre></div></div>

<p>To use it, just run:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family: Monaco, monospace;">.<span class="sy0">/</span>createdb testdb testuser secretpass</pre></div></div>

<p>That command would create a database named <i>testdb</i>, and user <i>testuser</i> with the password of <i>secretpass</i>.</p>
]]></content:encoded>
			<wfw:commentRss>http://jetpackweb.com/blog/2009/07/20/bash-script-to-create-mysql-database-and-user/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>How to fix Munin&#8217;s MySQL Graph on cPanel</title>
		<link>http://jetpackweb.com/blog/2009/07/16/how-to-fix-munins-mysql-graph-on-cpanel/</link>
		<comments>http://jetpackweb.com/blog/2009/07/16/how-to-fix-munins-mysql-graph-on-cpanel/#comments</comments>
		<pubDate>Thu, 16 Jul 2009 16:54:51 +0000</pubDate>
		<dc:creator>Brian Racer</dc:creator>
				<category><![CDATA[cpanel]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[sysadmin]]></category>
		<category><![CDATA[munin]]></category>

		<guid isPermaLink="false">http://jetpackweb.com/blog/?p=105</guid>
		<description><![CDATA[We have a few cPanel servers deployed and to visually monitor performance we use the Munin monitoring tool. We were having issues where the MySQL graphs would stop updating. The bug has to do with one of the perl libraries the script uses, which causes the MySQL plugin to have problems location the mysqladmin program. [...]]]></description>
			<content:encoded><![CDATA[<p>We have a few cPanel servers deployed and to visually monitor performance we use the Munin monitoring tool. We were having issues where the MySQL graphs would stop updating. The bug has to do with one of the perl libraries the script uses, which causes the MySQL plugin to have problems location the <b>mysqladmin</b> program.</p>
<p>To fix these, create or edit the following file:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family: Monaco, monospace;"><span class="kw2">vi</span> <span class="sy0">/</span>etc<span class="sy0">/</span>munin<span class="sy0">/</span>plugin-conf.d<span class="sy0">/</span>cpanel.conf</pre></div></div>

<p>It should contain the following:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family: Monaco, monospace;"><span class="br0">&#91;</span>mysql<span class="sy0">*</span><span class="br0">&#93;</span>
user root
group wheel
env.mysqladmin <span class="sy0">/</span>usr<span class="sy0">/</span>bin<span class="sy0">/</span>mysqladmin
env.mysqlopts <span class="re5">--defaults-extra-file</span>=<span class="sy0">/</span>root<span class="sy0">/</span>.my.cnf</pre></div></div>

<p>This would load the username and password from root&#8217;s mysql config. If that file doesn&#8217;t exist you can create it:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family: Monaco, monospace;"><span class="kw2">sudo</span> <span class="kw2">vi</span> <span class="sy0">/</span>root<span class="sy0">/</span>.my.cnf</pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family: Monaco, monospace;"><span class="br0">&#91;</span>client<span class="br0">&#93;</span>
<span class="re2">user</span>=<span class="st0">&quot;root&quot;</span>
<span class="re2">pass</span>=<span class="st0">&quot;secret!password&quot;</span></pre></div></div>

<p>Now just restart Munin, wait a a little bit, and the graphs should start populating again!</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family: Monaco, monospace;"><span class="kw2">sudo</span> <span class="sy0">/</span>etc<span class="sy0">/</span>init.d<span class="sy0">/</span>munin-node restart</pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://jetpackweb.com/blog/2009/07/16/how-to-fix-munins-mysql-graph-on-cpanel/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Using Maatkit to batch convert MySQL storage engines</title>
		<link>http://jetpackweb.com/blog/2009/07/15/using-maatkit-to-batch-convert-mysql-storage-engines/</link>
		<comments>http://jetpackweb.com/blog/2009/07/15/using-maatkit-to-batch-convert-mysql-storage-engines/#comments</comments>
		<pubDate>Wed, 15 Jul 2009 17:08:04 +0000</pubDate>
		<dc:creator>Brian Racer</dc:creator>
				<category><![CDATA[mysql]]></category>

		<guid isPermaLink="false">http://jetpackweb.com/blog/?p=75</guid>
		<description><![CDATA[Recently I was working with a client who imported a couple databases, each that had thousands of InnoDB tables taking up tens of gigabytes of data to a new server. Unfortunately the InnoDB engine was misconfiguration and therefore not loaded at the time of import. MySQL silently created all these tables as MyISAM instead. Not [...]]]></description>
			<content:encoded><![CDATA[<p>Recently I was working with a client who imported a couple databases, each that had thousands of InnoDB tables taking up tens of gigabytes of data to a new server. Unfortunately the InnoDB engine was misconfiguration and therefore not loaded at the time of import. MySQL silently created all these tables as MyISAM instead. Not wanting to wait hours for the import process to proceed again, I used a program from the excellent <a href="http://www.maatkit.org/" target="_blank">Maatkit</a> package: <a href="http://www.maatkit.org/doc/mk-find.html" target="_blank">mk-find</a>. It works similar to the unix find command, except it works on the MySQL server.</p>
<p>The following command will find all MyISAM tables from a certain database and convert them to InnoDB:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family: Monaco, monospace;">mk-find <span class="sy0">&lt;</span>db_name<span class="sy0">&gt;</span> <span class="re5">--engine</span> MyISAM <span class="re5">--exec</span> <span class="st0">&quot;ALTER TABLE %D.%N ENGINE=INNODB&quot;</span> <span class="re5">--print</span></pre></div></div>

<p>You can download the latest version from Maatkit&#8217;s <a href="http://code.google.com/p/maatkit/" target="_blank">Google Code</a> page.</p>
]]></content:encoded>
			<wfw:commentRss>http://jetpackweb.com/blog/2009/07/15/using-maatkit-to-batch-convert-mysql-storage-engines/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
