<?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>youdidwhatwithtsql.com &#187; MySQL</title>
	<atom:link href="http://www.youdidwhatwithtsql.com/category/mysql/feed" rel="self" type="application/rss+xml" />
	<link>http://www.youdidwhatwithtsql.com</link>
	<description>making DBAs everywhere curse!</description>
	<lastBuildDate>Tue, 31 Jan 2012 12:21:23 +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>MySQL Storage engine benchmarking</title>
		<link>http://www.youdidwhatwithtsql.com/mysql-storage-engine-benchmarking/1384</link>
		<comments>http://www.youdidwhatwithtsql.com/mysql-storage-engine-benchmarking/1384#comments</comments>
		<pubDate>Mon, 07 Nov 2011 20:49:37 +0000</pubDate>
		<dc:creator>Rhys</dc:creator>
				<category><![CDATA[DBA]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[Benchmark]]></category>
		<category><![CDATA[InnoDB]]></category>
		<category><![CDATA[MyISAM]]></category>

		<guid isPermaLink="false">http://www.youdidwhatwithtsql.com/mysql-storage-engine-benchmarking/1384</guid>
		<description><![CDATA[Here&#8217;s a stored procedure I use to perform some simple benchmarking of inserts for MySQL. It takes three parameters; p_table_type which should be set to the storage engine you wish to benchmark i.e. &#8216;MyISAM&#8217;, &#8216;InnoDB&#8217;, p_inserts; set this to the number of inserts to perform. p_autocommit; set the autocommit variable (relevant to InnoDB only) to [...]<p>Post from: <a href="http://www.youdidwhatwithtsql.com">youdidwhatwithtsql.com</a><br/><br/><a href="http://www.youdidwhatwithtsql.com/mysql-storage-engine-benchmarking/1384">MySQL Storage engine benchmarking</a></p>
]]></description>
			<content:encoded><![CDATA[<p>Here&#8217;s a stored procedure I use to perform some simple benchmarking of inserts for <a title="MySQL" href="http://dev.mysql.com" target="_blank">MySQL</a>. It takes three parameters; <strong>p_table_type</strong> which should be set to the storage engine you wish to benchmark i.e. &#8216;MyISAM&#8217;, &#8216;InnoDB&#8217;, <strong>p_inserts</strong>; set this to the number of inserts to perform. <strong>p_autocommit</strong>; set the <a title="InnoDB autocommit variable" href="http://dev.mysql.com/doc/refman/5.0/en/innodb-transaction-model.html" target="_blank">autocommit</a> variable (relevant to <a title="InnoDB Storage Engine" href="http://www.innodb.com/" target="_blank">InnoDB</a> only) to 0 or 1.</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p1384code5'); return false;">View Code</a> MYSQL</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p13845"><td class="code" id="p1384code5"><pre class="mysql" style="font-family:monospace;">DELIMITER $$
<span style="color: #990099; font-weight: bold;">USE</span> <span style="color: #008000;">`test`</span>$$
<span style="color: #990099; font-weight: bold;">DROP</span> <span style="color: #990099; font-weight: bold;">PROCEDURE</span> <span style="color: #009900;">IF</span> <span style="color: #990099; font-weight: bold;">EXISTS</span> <span style="color: #008000;">`table<span style="color: #008080; font-weight: bold;">_</span>engine<span style="color: #008080; font-weight: bold;">_</span>test`</span>$$
        <span style="color: #990099; font-weight: bold;">CREATE</span> <span style="color: #990099; font-weight: bold;">DEFINER</span><span style="color: #CC0099;">=</span><span style="color: #008000;">`root`</span>@<span style="color: #008000;">`<span style="color: #008080; font-weight: bold;">%</span>`</span>
        <span style="color: #990099; font-weight: bold;">PROCEDURE</span> <span style="color: #008000;">`table<span style="color: #008080; font-weight: bold;">_</span>engine<span style="color: #008080; font-weight: bold;">_</span>test`</span><span style="color: #FF00FF;">&#40;</span><span style="color: #990099; font-weight: bold;">IN</span> p_table_type <span style="color: #999900; font-weight: bold;">VARCHAR</span><span style="color: #FF00FF;">&#40;</span><span style="color: #008080;">20</span><span style="color: #FF00FF;">&#41;</span><span style="color: #000033;">,</span>
                                      <span style="color: #990099; font-weight: bold;">IN</span> p_inserts    <span style="color: #999900; font-weight: bold;">INT</span><span style="color: #000033;">,</span>
                                      <span style="color: #990099; font-weight: bold;">IN</span> p_autocommit <span style="color: #999900; font-weight: bold;">TINYINT</span><span style="color: #FF00FF;">&#41;</span>
                <span style="color: #990099; font-weight: bold;">SQL SECURITY</span> <span style="color: #990099; font-weight: bold;">INVOKER</span>
        <span style="color: #990099; font-weight: bold;">BEGIN</span>
&nbsp;
                <span style="color: #990099; font-weight: bold;">DECLARE</span> sql_string <span style="color: #999900; font-weight: bold;">VARCHAR</span><span style="color: #FF00FF;">&#40;</span><span style="color: #008080;">300</span><span style="color: #FF00FF;">&#41;</span><span style="color: #000033;">;</span>
&nbsp;
                <span style="color: #808080; font-style: italic;"># Set session autocommit</span>
                <span style="color: #990099; font-weight: bold;">SET</span> <span style="color: #990099; font-weight: bold;">SESSION</span> autocommit <span style="color: #CC0099;">=</span> p_autocommit<span style="color: #000033;">;</span>
&nbsp;
                <span style="color: #808080; font-style: italic;"># TABLE TO hold session times</span>
                <span style="color: #990099; font-weight: bold;">CREATE</span> <span style="color: #990099; font-weight: bold;">TABLE</span> <span style="color: #990099; font-weight: bold;">IF <span style="color: #CC0099; font-weight: bold;">NOT</span> EXISTS</span> test_session
                             <span style="color: #FF00FF;">&#40;</span>
                                          Id         <span style="color: #999900; font-weight: bold;">INT</span> <span style="color: #CC0099; font-weight: bold;">NOT</span> <span style="color: #9900FF; font-weight: bold;">NULL</span> <span style="color: #990099; font-weight: bold;">PRIMARY KEY</span> <span style="color: #FF9900; font-weight: bold;">AUTO_INCREMENT</span><span style="color: #000033;">,</span>
                                          table_type <span style="color: #999900; font-weight: bold;">VARCHAR</span><span style="color: #FF00FF;">&#40;</span><span style="color: #008080;">20</span><span style="color: #FF00FF;">&#41;</span> <span style="color: #CC0099; font-weight: bold;">NOT</span> <span style="color: #9900FF; font-weight: bold;">NULL</span>                   <span style="color: #000033;">,</span>
                                          inserts <span style="color: #999900; font-weight: bold;">INT</span> <span style="color: #CC0099; font-weight: bold;">NOT</span> <span style="color: #9900FF; font-weight: bold;">NULL</span><span style="color: #000033;">,</span>
                                          autocommit <span style="color: #999900; font-weight: bold;">TINYINT</span> <span style="color: #CC0099; font-weight: bold;">NOT</span> <span style="color: #9900FF; font-weight: bold;">NULL</span><span style="color: #000033;">,</span>
                                          started    <span style="color: #999900; font-weight: bold;">DATETIME</span> <span style="color: #9900FF; font-weight: bold;">NULL</span>                          <span style="color: #000033;">,</span>
                                          finished   <span style="color: #999900; font-weight: bold;">DATETIME</span> <span style="color: #9900FF; font-weight: bold;">NULL</span>
                             <span style="color: #FF00FF;">&#41;</span><span style="color: #000033;">;</span>
&nbsp;
                <span style="color: #990099; font-weight: bold;">CREATE</span> <span style="color: #990099; font-weight: bold;">TABLE</span> <span style="color: #990099; font-weight: bold;">IF <span style="color: #CC0099; font-weight: bold;">NOT</span> EXISTS</span> test_session_inserts
                             <span style="color: #FF00FF;">&#40;</span>
                                          id              <span style="color: #999900; font-weight: bold;">INTEGER</span> <span style="color: #CC0099; font-weight: bold;">NOT</span> <span style="color: #9900FF; font-weight: bold;">NULL</span> <span style="color: #990099; font-weight: bold;">PRIMARY KEY</span> <span style="color: #FF9900; font-weight: bold;">AUTO_INCREMENT</span><span style="color: #000033;">,</span>
                                          test_session_id <span style="color: #999900; font-weight: bold;">INTEGER</span> <span style="color: #CC0099; font-weight: bold;">NOT</span> <span style="color: #9900FF; font-weight: bold;">NULL</span>                           <span style="color: #000033;">,</span>
                                          started         <span style="color: #999900; font-weight: bold;">DATETIME</span> <span style="color: #CC0099; font-weight: bold;">NOT</span> <span style="color: #9900FF; font-weight: bold;">NULL</span>                          <span style="color: #000033;">,</span>
                                          finished        <span style="color: #999900; font-weight: bold;">DATETIME</span> <span style="color: #CC0099; font-weight: bold;">NOT</span> <span style="color: #9900FF; font-weight: bold;">NULL</span>
                             <span style="color: #FF00FF;">&#41;</span><span style="color: #000033;">;</span>
&nbsp;
                <span style="color: #808080; font-style: italic;"># clean up ANY existing test TABLE</span>
                <span style="color: #990099; font-weight: bold;">DROP</span> <span style="color: #990099; font-weight: bold;">TABLE</span> <span style="color: #009900;">IF</span> <span style="color: #990099; font-weight: bold;">EXISTS</span> test_table_type<span style="color: #000033;">;</span>
&nbsp;
                <span style="color: #990099; font-weight: bold;">SET</span> sql_string <span style="color: #CC0099;">=</span> <span style="color: #000099;">CONCAT</span><span style="color: #FF00FF;">&#40;</span><span style="color: #008000;">'CREATE TABLE test<span style="color: #008080; font-weight: bold;">_</span>table<span style="color: #008080; font-weight: bold;">_</span>type
					(
						id INTEGER NOT NULL PRIMARY KEY AUTO<span style="color: #008080; font-weight: bold;">_</span>INCREMENT,
						random INTEGER,
						text1 VARCHAR(10) NOT NULL,
						text2 VARCHAR(10) NOT NULL
					)ENGINE = '</span><span style="color: #000033;">,</span> p_table_type<span style="color: #FF00FF;">&#41;</span><span style="color: #000033;">;</span>
                <span style="color: #808080; font-style: italic;"># PREPARE SQL AND EXECUTE</span>
                <span style="color: #990099; font-weight: bold;">SET</span> @q <span style="color: #CC0099;">=</span> sql_string<span style="color: #000033;">;</span>
                PREPARE stmt <span style="color: #990099; font-weight: bold;">FROM</span> @q<span style="color: #000033;">;</span>
                EXECUTE stmt<span style="color: #000033;">;</span>
                DEALLOCATE PREPARE stmt<span style="color: #000033;">;</span>
                <span style="color: #808080; font-style: italic;"># START the test session</span>
                <span style="color: #990099; font-weight: bold;">INSERT</span>
                <span style="color: #990099; font-weight: bold;">INTO</span>   test_session
                       <span style="color: #FF00FF;">&#40;</span>
                              table_type<span style="color: #000033;">,</span>
                              inserts<span style="color: #000033;">,</span>
                              autocommit<span style="color: #000033;">,</span>
                              started
                       <span style="color: #FF00FF;">&#41;</span>
                       <span style="color: #990099; font-weight: bold;">VALUES</span>
                       <span style="color: #FF00FF;">&#40;</span>
                              p_table_type<span style="color: #000033;">,</span>
                              p_inserts<span style="color: #000033;">,</span>
                              p_autocommit<span style="color: #000033;">,</span>
                              <span style="color: #000099;">NOW</span><span style="color: #FF00FF;">&#40;</span><span style="color: #FF00FF;">&#41;</span>
                       <span style="color: #FF00FF;">&#41;</span><span style="color: #000033;">;</span>
&nbsp;
                <span style="color: #990099; font-weight: bold;">SET</span> @id               <span style="color: #CC0099;">=</span> <span style="color: #000099;">LAST_INSERT_ID</span><span style="color: #FF00FF;">&#40;</span><span style="color: #FF00FF;">&#41;</span><span style="color: #000033;">;</span>
                <span style="color: #990099; font-weight: bold;">SET</span> @i                <span style="color: #CC0099;">=</span> <span style="color: #008080;">0</span><span style="color: #000033;">;</span>
                while_loop: WHILE <span style="color: #FF00FF;">&#40;</span>@i <span style="color: #CC0099;">&lt;</span> p_inserts<span style="color: #FF00FF;">&#41;</span> <span style="color: #990099; font-weight: bold;">DO</span>
                <span style="color: #808080; font-style: italic;"># Generate VALUES for insert</span>
                <span style="color: #990099; font-weight: bold;">SET</span> @random  <span style="color: #CC0099;">=</span> <span style="color: #000099;">RAND</span><span style="color: #FF00FF;">&#40;</span><span style="color: #FF00FF;">&#41;</span><span style="color: #000033;">;</span>
                <span style="color: #990099; font-weight: bold;">SET</span> @text1   <span style="color: #CC0099;">=</span> <span style="color: #000099;">SUBSTRING</span><span style="color: #FF00FF;">&#40;</span><span style="color: #000099;">MD5</span><span style="color: #FF00FF;">&#40;</span><span style="color: #000099;">RAND</span><span style="color: #FF00FF;">&#40;</span><span style="color: #FF00FF;">&#41;</span><span style="color: #FF00FF;">&#41;</span><span style="color: #000033;">,</span> <span style="color: #CC0099;">-</span><span style="color: #008080;">10</span><span style="color: #FF00FF;">&#41;</span><span style="color: #000033;">;</span>
                <span style="color: #990099; font-weight: bold;">SET</span> @text2   <span style="color: #CC0099;">=</span> <span style="color: #000099;">SUBSTRING</span><span style="color: #FF00FF;">&#40;</span><span style="color: #000099;">MD5</span><span style="color: #FF00FF;">&#40;</span><span style="color: #000099;">RAND</span><span style="color: #FF00FF;">&#40;</span><span style="color: #FF00FF;">&#41;</span><span style="color: #FF00FF;">&#41;</span><span style="color: #000033;">,</span> <span style="color: #CC0099;">-</span><span style="color: #008080;">10</span><span style="color: #FF00FF;">&#41;</span><span style="color: #000033;">;</span>
                <span style="color: #990099; font-weight: bold;">SET</span> @started <span style="color: #CC0099;">=</span> <span style="color: #000099;">NOW</span><span style="color: #FF00FF;">&#40;</span><span style="color: #FF00FF;">&#41;</span><span style="color: #000033;">;</span>
                <span style="color: #808080; font-style: italic;"># INSERT the test row</span>
                <span style="color: #990099; font-weight: bold;">INSERT</span>
                <span style="color: #990099; font-weight: bold;">INTO</span>   test_table_type
                       <span style="color: #FF00FF;">&#40;</span>
                              random<span style="color: #000033;">,</span>
                              text1 <span style="color: #000033;">,</span>
                              text2
                       <span style="color: #FF00FF;">&#41;</span>
                       <span style="color: #990099; font-weight: bold;">VALUES</span>
                       <span style="color: #FF00FF;">&#40;</span>
                              @random<span style="color: #000033;">,</span>
                              @text1 <span style="color: #000033;">,</span>
                              @text2
                       <span style="color: #FF00FF;">&#41;</span><span style="color: #000033;">;</span>
&nbsp;
                <span style="color: #808080; font-style: italic;"># record INSERT times</span>
                        <span style="color: #990099; font-weight: bold;">INSERT</span>
                        <span style="color: #990099; font-weight: bold;">INTO</span>   test_session_inserts
                               <span style="color: #FF00FF;">&#40;</span>
                                      test_session_id<span style="color: #000033;">,</span>
                                      started        <span style="color: #000033;">,</span>
                                      finished
                               <span style="color: #FF00FF;">&#41;</span>
                               <span style="color: #990099; font-weight: bold;">VALUES</span>
                               <span style="color: #FF00FF;">&#40;</span>
                                      @id     <span style="color: #000033;">,</span>
                                      @started<span style="color: #000033;">,</span>
                                      <span style="color: #000099;">NOW</span><span style="color: #FF00FF;">&#40;</span><span style="color: #FF00FF;">&#41;</span>
                               <span style="color: #FF00FF;">&#41;</span><span style="color: #000033;">;</span>
&nbsp;
                        <span style="color: #808080; font-style: italic;"># increment counter</span>
                        <span style="color: #990099; font-weight: bold;">SET</span> @i <span style="color: #CC0099;">=</span> @i <span style="color: #CC0099;">+</span> <span style="color: #008080;">1</span><span style="color: #000033;">;</span>
                <span style="color: #009900;">END</span> WHILE while_loop<span style="color: #000033;">;</span>
                <span style="color: #808080; font-style: italic;"># Finish the session</span>
                <span style="color: #990099; font-weight: bold;">UPDATE</span> test_session
                <span style="color: #990099; font-weight: bold;">SET</span>    finished <span style="color: #CC0099;">=</span> <span style="color: #000099;">NOW</span><span style="color: #FF00FF;">&#40;</span><span style="color: #FF00FF;">&#41;</span>
                <span style="color: #990099; font-weight: bold;">WHERE</span>  id       <span style="color: #CC0099;">=</span> @id<span style="color: #000033;">;</span>
&nbsp;
<span style="color: #009900;">END</span>$$
DELIMITER <span style="color: #000033;">;</span></pre></td></tr></table></div>

<p>Run your tests like so&#8230;</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p1384code6'); return false;">View Code</a> MYSQL</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p13846"><td class="code" id="p1384code6"><pre class="mysql" style="font-family:monospace;"><span style="color: #990099; font-weight: bold;">CALL</span> table_engine_test<span style="color: #FF00FF;">&#40;</span><span style="color: #008000;">'MyISAM'</span><span style="color: #000033;">,</span> <span style="color: #008080;">10000</span><span style="color: #000033;">,</span> <span style="color: #008080;">0</span><span style="color: #FF00FF;">&#41;</span><span style="color: #000033;">;</span>
<span style="color: #990099; font-weight: bold;">CALL</span> table_engine_test<span style="color: #FF00FF;">&#40;</span><span style="color: #008000;">'InnoDB'</span><span style="color: #000033;">,</span> <span style="color: #008080;">10000</span><span style="color: #000033;">,</span> <span style="color: #008080;">0</span><span style="color: #FF00FF;">&#41;</span><span style="color: #000033;">;</span>
<span style="color: #990099; font-weight: bold;">CALL</span> table_engine_test<span style="color: #FF00FF;">&#40;</span><span style="color: #008000;">'InnoDB'</span><span style="color: #000033;">,</span> <span style="color: #008080;">10000</span><span style="color: #000033;">,</span> <span style="color: #008080;">1</span><span style="color: #FF00FF;">&#41;</span><span style="color: #000033;">;</span>
<span style="color: #990099; font-weight: bold;">CALL</span> table_engine_test<span style="color: #FF00FF;">&#40;</span><span style="color: #008000;">'MyISAM'</span><span style="color: #000033;">,</span> <span style="color: #008080;">100000</span><span style="color: #000033;">,</span> <span style="color: #008080;">0</span><span style="color: #FF00FF;">&#41;</span><span style="color: #000033;">;</span>
<span style="color: #990099; font-weight: bold;">CALL</span> table_engine_test<span style="color: #FF00FF;">&#40;</span><span style="color: #008000;">'InnoDB'</span><span style="color: #000033;">,</span> <span style="color: #008080;">100000</span><span style="color: #000033;">,</span> <span style="color: #008080;">0</span><span style="color: #FF00FF;">&#41;</span><span style="color: #000033;">;</span>
<span style="color: #990099; font-weight: bold;">CALL</span> table_engine_test<span style="color: #FF00FF;">&#40;</span><span style="color: #008000;">'InnoDB'</span><span style="color: #000033;">,</span> <span style="color: #008080;">100000</span><span style="color: #000033;">,</span> <span style="color: #008080;">1</span><span style="color: #FF00FF;">&#41;</span><span style="color: #000033;">;</span></pre></td></tr></table></div>

<p>The <strong>test_session</strong> contains some summary information about each of the tests;</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p1384code7'); return false;">View Code</a> MYSQL</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p13847"><td class="code" id="p1384code7"><pre class="mysql" style="font-family:monospace;"><span style="color: #990099; font-weight: bold;">SELECT</span> <span style="color: #CC0099;">*</span>
<span style="color: #990099; font-weight: bold;">FROM</span> test_session<span style="color: #000033;">;</span></pre></td></tr></table></div>

<p><a href="http://www.youdidwhatwithtsql.com/wp-content/uploads/2011/11/mysql_table_engine_test.png"><img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border-width: 0px;" title="mysql_table_engine_test" src="http://www.youdidwhatwithtsql.com/wp-content/uploads/2011/11/mysql_table_engine_test_thumb.png" alt="mysql table engine test thumb MySQL Storage engine benchmarking" width="644" height="166" border="0" /></a></p>
<p>Calculate the time taken for each test with the following query;</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p1384code8'); return false;">View Code</a> MYSQL</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p13848"><td class="code" id="p1384code8"><pre class="mysql" style="font-family:monospace;"><span style="color: #990099; font-weight: bold;">SELECT</span> <span style="color: #CC0099;">*</span><span style="color: #000033;">,</span> TIMEDIFF<span style="color: #FF00FF;">&#40;</span>finished<span style="color: #000033;">,</span> started<span style="color: #FF00FF;">&#41;</span> <span style="color: #990099; font-weight: bold;">AS</span> seconds
<span style="color: #990099; font-weight: bold;">FROM</span> test_session<span style="color: #000033;">;</span></pre></td></tr></table></div>

<p>Happy Benchmarking!</p>
<p><map name='google_ad_map_1384_a45beff5d2e172f6'>
<area shape='rect' href='http://imageads.googleadservices.com/pagead/imgclick/1384?pos=0' coords='1,2,367,28' />
<area shape='rect' href='http://services.google.com/feedback/abg' coords='384,10,453,23'/></map>
<img usemap='#google_ad_map_1384_a45beff5d2e172f6' border='0' src='http://imageads.googleadservices.com/pagead/ads?format=468x30_aff_img&amp;client=&amp;channel=&amp;output=png&amp;cuid=1384&amp;url=http%3A%2F%2Fwww.youdidwhatwithtsql.com%2Fmysql-storage-engine-benchmarking%2F1384' title="MySQL Storage engine benchmarking" alt=" MySQL Storage engine benchmarking" /></p><p>Post from: <a href="http://www.youdidwhatwithtsql.com">youdidwhatwithtsql.com</a><br/><br/><a href="http://www.youdidwhatwithtsql.com/mysql-storage-engine-benchmarking/1384">MySQL Storage engine benchmarking</a></p>
<div class="none"><div class="g-plusone" data-href="http://www.youdidwhatwithtsql.com/mysql-storage-engine-benchmarking/1384" size="standard" count="true"></div></div>]]></content:encoded>
			<wfw:commentRss>http://www.youdidwhatwithtsql.com/mysql-storage-engine-benchmarking/1384/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Synchronize Mysql slave tables with mk-table-sync</title>
		<link>http://www.youdidwhatwithtsql.com/synchronize-mysql-slave-tables-with-mk-table-sync/1270</link>
		<comments>http://www.youdidwhatwithtsql.com/synchronize-mysql-slave-tables-with-mk-table-sync/1270#comments</comments>
		<pubDate>Tue, 21 Jun 2011 19:40:56 +0000</pubDate>
		<dc:creator>Rhys</dc:creator>
				<category><![CDATA[DBA]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[maatkit]]></category>
		<category><![CDATA[slaves]]></category>

		<guid isPermaLink="false">http://www.youdidwhatwithtsql.com/synchronize-mysql-slave-tables-with-mk-table-sync/1270</guid>
		<description><![CDATA[I&#8217;ve been meaning to check out Maatkit for a while now. Today I had a reason to as one of our MySQL slaves got out of sync with the master. I&#8217;d heard about mk-table-sync, a tool that synchronizes tables, so I thought I&#8217;d give it a shot. As it turns out it&#8217;s this easy; mk-table-sync [...]<p>Post from: <a href="http://www.youdidwhatwithtsql.com">youdidwhatwithtsql.com</a><br/><br/><a href="http://www.youdidwhatwithtsql.com/synchronize-mysql-slave-tables-with-mk-table-sync/1270">Synchronize Mysql slave tables with mk-table-sync</a></p>
]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been meaning to check out <a title="Maatkit MySQL tools" href="http://www.maatkit.org/" target="_blank">Maatkit</a> for a while now. Today I had a reason to as one of our MySQL slaves got out of sync with the master. I&#8217;d heard about <a href="http://www.maatkit.org/doc/mk-table-sync.html" target="_blank">mk-table-sync</a>, a tool that synchronizes tables, so I thought I&#8217;d give it a shot.</p>
<p>As it turns out it&#8217;s this easy;</p>
<pre>mk-table-sync --execute h=slave_server,u=username,p=secret,D=database,t=table_to_sync --sync-to-master</pre>
<p>I was a little worried about how this would pan out as I assumed it would change data on the slave. Cleverly, the Maatkit developers have thought of this;</p>
<p><em>&quot;When synchronizing a server that is a replication slave with the &#8211;replicate or &#8211;sync-to-master methods, it <strong>always</strong> makes the changes on the replication master, <strong>never</strong> the replication slave directly.&quot; </em><a href="http://www.maatkit.org/doc/mk-table-sync.html" target="_blank">ref</a></p>
<p>So in theory this should alleviate some of those replication pains. Happy days!</p>
<p><map name='google_ad_map_1270_a45beff5d2e172f6'>
<area shape='rect' href='http://imageads.googleadservices.com/pagead/imgclick/1270?pos=0' coords='1,2,367,28' />
<area shape='rect' href='http://services.google.com/feedback/abg' coords='384,10,453,23'/></map>
<img usemap='#google_ad_map_1270_a45beff5d2e172f6' border='0' src='http://imageads.googleadservices.com/pagead/ads?format=468x30_aff_img&amp;client=&amp;channel=&amp;output=png&amp;cuid=1270&amp;url=http%3A%2F%2Fwww.youdidwhatwithtsql.com%2Fsynchronize-mysql-slave-tables-with-mk-table-sync%2F1270' title="Synchronize Mysql slave tables with mk table sync" alt=" Synchronize Mysql slave tables with mk table sync" /></p><p>Post from: <a href="http://www.youdidwhatwithtsql.com">youdidwhatwithtsql.com</a><br/><br/><a href="http://www.youdidwhatwithtsql.com/synchronize-mysql-slave-tables-with-mk-table-sync/1270">Synchronize Mysql slave tables with mk-table-sync</a></p>
<div class="none"><div class="g-plusone" data-href="http://www.youdidwhatwithtsql.com/synchronize-mysql-slave-tables-with-mk-table-sync/1270" size="standard" count="true"></div></div>]]></content:encoded>
			<wfw:commentRss>http://www.youdidwhatwithtsql.com/synchronize-mysql-slave-tables-with-mk-table-sync/1270/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Backing up the structure of MySQL databases</title>
		<link>http://www.youdidwhatwithtsql.com/backing-up-the-structure-of-mysql-databases/1063</link>
		<comments>http://www.youdidwhatwithtsql.com/backing-up-the-structure-of-mysql-databases/1063#comments</comments>
		<pubDate>Tue, 25 Jan 2011 21:00:20 +0000</pubDate>
		<dc:creator>Rhys</dc:creator>
				<category><![CDATA[DBA]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[Bash]]></category>
		<category><![CDATA[mysqldump]]></category>

		<guid isPermaLink="false">http://www.youdidwhatwithtsql.com/backing-up-the-structure-of-mysql-databases/1063</guid>
		<description><![CDATA[Today I wanted a quick and easy way to generate a backup of the structure of all MySQL databases in one easy hit. Here&#8217;s a couple of ways you can do this with the tools you&#8217;re likely to find everywhere. Firstly, we can use the following query to generate a list of mysqldump commands. The [...]<p>Post from: <a href="http://www.youdidwhatwithtsql.com">youdidwhatwithtsql.com</a><br/><br/><a href="http://www.youdidwhatwithtsql.com/backing-up-the-structure-of-mysql-databases/1063">Backing up the structure of MySQL databases</a></p>
]]></description>
			<content:encoded><![CDATA[<p>Today I wanted a quick and easy way to generate a backup of the structure of all MySQL databases in one easy hit. Here&#8217;s a couple of ways you can do this with the tools you&#8217;re likely to find everywhere.</p>
<p>Firstly, we can use the following query to generate a list of <a title="mysqldump database backup program" href="http://dev.mysql.com/doc/refman/5.1/en/mysqldump.html" target="_blank">mysqldump</a> commands. The backups generated here pretty much just contain tables, triggers and functions so customise the command to your needs. Just change the output directory from .<strong>/home/rhys</strong>.</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p1063code12'); return false;">View Code</a> MYSQL</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p106312"><td class="code" id="p1063code12"><pre class="mysql" style="font-family:monospace;"><span style="color: #990099; font-weight: bold;">SELECT</span> <span style="color: #000099;">CONCAT</span><span style="color: #FF00FF;">&#40;</span><span style="color: #008000;">'mysqldump -d --routines -h mysql<span style="color: #008080; font-weight: bold;">_</span>host -u username -pSecret '</span><span style="color: #000033;">,</span> SCHEMA_NAME<span style="color: #000033;">,</span> <span style="color: #008000;">' &gt; &quot;/home/rhys/Desktop/'</span><span style="color: #000033;">,</span> SCHEMA_NAME<span style="color: #000033;">,</span> <span style="color: #008000;">'.sql&quot;'</span><span style="color: #FF00FF;">&#41;</span>
<span style="color: #990099; font-weight: bold;">FROM</span> INFORMATION_SCHEMA.SCHEMATA
<span style="color: #990099; font-weight: bold;">WHERE</span> SCHEMA_NAME <span style="color: #CC0099; font-weight: bold;">NOT</span> <span style="color: #990099; font-weight: bold;">IN</span> <span style="color: #FF00FF;">&#40;</span><span style="color: #008000;">'mysql'</span><span style="color: #000033;">,</span> <span style="color: #008000;">'information<span style="color: #008080; font-weight: bold;">_</span>schema'</span><span style="color: #000033;">,</span> <span style="color: #008000;">'performance<span style="color: #008080; font-weight: bold;">_</span>schema'</span><span style="color: #FF00FF;">&#41;</span><span style="color: #000033;">;</span></pre></td></tr></table></div>

<p>These commands can be copied and then pasted into a terminal to be executed.</p>
<p>Here&#8217;s a pure bash way of achieving the same thing. The script is called on the command line with the MySQL host, user name and password supplied as parameters. Backups are generated in the current users home directory in the format <strong>db_name.sql</strong>.</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p1063code13'); return false;">View Code</a> BASH</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p106313"><td class="code" id="p1063code13"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#!/bin/bash</span>
<span style="color: #666666; font-style: italic;"># MySQL details passed on command line</span>
<span style="color: #007800;">HOST</span>=<span style="color: #007800;">$1</span>
<span style="color: #007800;">USER</span>=<span style="color: #007800;">$2</span>;
<span style="color: #007800;">PWD</span>=<span style="color: #007800;">$3</span>;
&nbsp;
<span style="color: #666666; font-style: italic;"># Query to get database excluding a few system ones</span>
<span style="color: #007800;">QUERY</span>=<span style="color: #ff0000;">&quot;SELECT SCHEMA_NAME FROM INFORMATION_SCHEMA.SCHEMATA WHERE SCHEMA_NAME NOT IN ('mysql','information_schema','performance_schema')&quot;</span>;
<span style="color: #666666; font-style: italic;"># Run the query and get the results</span>
<span style="color: #007800;">results</span>=<span style="color: #000000; font-weight: bold;">`</span>mysql <span style="color: #660033;">-h</span> <span style="color: #007800;">$HOST</span> <span style="color: #660033;">-u</span> <span style="color: #007800;">$USER</span> -p<span style="color: #007800;">$PWD</span> <span style="color: #660033;">-N</span> <span style="color: #660033;">-e</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$QUERY</span>&quot;</span><span style="color: #000000; font-weight: bold;">`</span>;
&nbsp;
<span style="color: #666666; font-style: italic;"># Loop through each row</span>
<span style="color: #000000; font-weight: bold;">for</span> db <span style="color: #000000; font-weight: bold;">in</span> <span style="color: #007800;">$results</span>
<span style="color: #000000; font-weight: bold;">do</span>
	<span style="color: #007800;">bkp</span>=<span style="color: #ff0000;">&quot;mysqldump -d --routines -h <span style="color: #007800;">$HOST</span> -u <span style="color: #007800;">$USER</span> -p<span style="color: #007800;">$PWD</span> <span style="color: #007800;">$db</span> &gt; '<span style="color: #007800;">$HOME</span>/<span style="color: #007800;">$db</span>.sql'&quot;</span>;
	<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Backing up <span style="color: #007800;">$db</span>...&quot;</span>;
	<span style="color: #7a0874; font-weight: bold;">eval</span> <span style="color: #007800;">$bkp</span>;
<span style="color: #000000; font-weight: bold;">done</span></pre></td></tr></table></div>

<p>Save this to a file called <strong>backup_mysql.sh</strong> and don;t forget to do a <strong>chmod + x</strong> to make the script executable. The backup can be executed from the command line with;</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p1063code14'); return false;">View Code</a> BASH</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p106314"><td class="code" id="p1063code14"><pre class="bash" style="font-family:monospace;">.<span style="color: #000000; font-weight: bold;">/</span>backup_mysql.sh localhost username password</pre></td></tr></table></div>

<p><a href="http://www.youdidwhatwithtsql.com/wp-content/uploads/2011/8f94a578fd9d_11B87/mysqldump_backup_databases.png"><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="mysqldump backup databases" border="0" alt="mysqldump backup databases thumb Backing up the structure of MySQL databases" src="http://www.youdidwhatwithtsql.com/wp-content/uploads/2011/8f94a578fd9d_11B87/mysqldump_backup_databases_thumb.png" width="644" height="429" /></a></p>
<p><map name='google_ad_map_1063_a45beff5d2e172f6'>
<area shape='rect' href='http://imageads.googleadservices.com/pagead/imgclick/1063?pos=0' coords='1,2,367,28' />
<area shape='rect' href='http://services.google.com/feedback/abg' coords='384,10,453,23'/></map>
<img usemap='#google_ad_map_1063_a45beff5d2e172f6' border='0' src='http://imageads.googleadservices.com/pagead/ads?format=468x30_aff_img&amp;client=&amp;channel=&amp;output=png&amp;cuid=1063&amp;url=http%3A%2F%2Fwww.youdidwhatwithtsql.com%2Fbacking-up-the-structure-of-mysql-databases%2F1063' title="Backing up the structure of MySQL databases" alt=" Backing up the structure of MySQL databases" /></p><p>Post from: <a href="http://www.youdidwhatwithtsql.com">youdidwhatwithtsql.com</a><br/><br/><a href="http://www.youdidwhatwithtsql.com/backing-up-the-structure-of-mysql-databases/1063">Backing up the structure of MySQL databases</a></p>
<div class="none"><div class="g-plusone" data-href="http://www.youdidwhatwithtsql.com/backing-up-the-structure-of-mysql-databases/1063" size="standard" count="true"></div></div>]]></content:encoded>
			<wfw:commentRss>http://www.youdidwhatwithtsql.com/backing-up-the-structure-of-mysql-databases/1063/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Add column headers to a MySQL Outfile</title>
		<link>http://www.youdidwhatwithtsql.com/add-column-headers-mysql-outfile/911</link>
		<comments>http://www.youdidwhatwithtsql.com/add-column-headers-mysql-outfile/911#comments</comments>
		<pubDate>Tue, 14 Dec 2010 21:11:30 +0000</pubDate>
		<dc:creator>Rhys</dc:creator>
				<category><![CDATA[DBA]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[MySQL]]></category>

		<guid isPermaLink="false">http://www.youdidwhatwithtsql.com/add-column-headers-to-a-mysql-outfile/911</guid>
		<description><![CDATA[Unfortunately the MySQL SELECT INTO OUTFILE command doesn&#8217;t support an option to output the headers of the result set you are exporting. A feature request has been open for over 2 years to sort this with no apparent activity. A few people have had the idea of using a UNION ALL to include the headers [...]<p>Post from: <a href="http://www.youdidwhatwithtsql.com">youdidwhatwithtsql.com</a><br/><br/><a href="http://www.youdidwhatwithtsql.com/add-column-headers-mysql-outfile/911">Add column headers to a MySQL Outfile</a></p>
]]></description>
			<content:encoded><![CDATA[<p>Unfortunately the <a title="MySQL SELECT INTO OUTFILE" href="http://dev.mysql.com/doc/refman/5.0/en/select.html" target="_blank">MySQL SELECT INTO OUTFILE</a> command doesn&#8217;t support an option to output the headers of the result set you are exporting. A <a title="Headers option for OUTFILE MySQL command" href="http://bugs.mysql.com/bug.php?id=34992" target="_blank">feature request</a> has been open for over 2 years to sort this with no apparent activity.</p>
<p> A few people have had the idea of using a <a title="MySQL SELECT INTO OUTFILE UNION" href="http://jasonswett.net/how-to-get-headers-when-using-mysqls-select-into-outfile/" target="_blank">UNION ALL to include the headers</a> but this becomes tedious with large queries. Tools like <a title="sqlyog" href="http://www.webyog.com/en/" target="_blank">sqlyog</a> are handy but can painfully slow for large result sets due to <a href="http://www.simple-talk.com/sql/t-sql-programming/rbar--row-by-agonizing-row/" target="_blank">RBAR</a> methods.</p>
<p>For large result sets I like to first run;</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p911code18'); return false;">View Code</a> MYSQL</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p91118"><td class="code" id="p911code18"><pre class="mysql" style="font-family:monospace;"><span style="color: #808080; font-style: italic;"># Create temp table</span>
<span style="color: #990099; font-weight: bold;">CREATE</span> <span style="color: #990099; font-weight: bold;">TEMPORARY</span> <span style="color: #990099; font-weight: bold;">TABLE</span> tmp_MyTable
<span style="color: #990099; font-weight: bold;">ENGINE</span> <span style="color: #CC0099;">=</span> MEMORY
<span style="color: #990099; font-weight: bold;">SELECT</span> col1<span style="color: #000033;">,</span> col2<span style="color: #000033;">,</span> col3<span style="color: #000033;">,</span> col4 <span style="color: #808080; font-style: italic;"># etc</span>
<span style="color: #990099; font-weight: bold;">FROM</span> myTable
<span style="color: #990099; font-weight: bold;">INNER</span> <span style="color: #990099; font-weight: bold;">JOIN</span> myTable2
	<span style="color: #990099; font-weight: bold;">ON</span> myTable.Id <span style="color: #CC0099;">=</span> myTable2.Id<span style="color: #000033;">;</span>
&nbsp;
<span style="color: #808080; font-style: italic;"># Get the column info</span>
<span style="color: #990099; font-weight: bold;">DESCRIBE</span> tmp_MyTable<span style="color: #000033;">;</span></pre></td></tr></table></div>

<p>This will output the result set we want to export into a temporary table. We can then get the column headers using the <a title="MySQL DESCRIBE command" href="http://dev.mysql.com/doc/refman/5.0/en/describe.html" target="_blank">DESCRIBE</a> command. Then I export my result set to a file using the OUTFILE command.</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p911code19'); return false;">View Code</a> MYSQL</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p91119"><td class="code" id="p911code19"><pre class="mysql" style="font-family:monospace;"><span style="color: #990099; font-weight: bold;">SELECT</span> <span style="color: #CC0099;">*</span>
<span style="color: #990099; font-weight: bold;">INTO</span> <span style="color: #990099; font-weight: bold;">OUTFILE</span> <span style="color: #008000;">'/home/user/export.csv'</span>
<span style="color: #990099; font-weight: bold;">FIELDS</span> <span style="color: #990099; font-weight: bold;">TERMINATED BY</span> <span style="color: #008000;">','</span>
<span style="color: #990099; font-weight: bold;">LINES</span> <span style="color: #990099; font-weight: bold;">TERMINATED BY</span> <span style="color: #008000;">'<span style="color: #004000; font-weight: bold;">\n</span>'</span>
<span style="color: #990099; font-weight: bold;">FROM</span> tmp_MyTable<span style="color: #000033;">;</span></pre></td></tr></table></div>

<p>Now it&#8217;s roll your sleeves up time with the Linux command-line and <a title="Unix SED command" href="http://en.wikipedia.org/wiki/Sed" target="_blank">sed</a>.</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p911code20'); return false;">View Code</a> BASH</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p91120"><td class="code" id="p911code20"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sed</span> <span style="color: #660033;">-i</span> <span style="color: #ff0000;">'1iOne,Two,Three,Four,Five'</span> <span style="color: #000000; font-weight: bold;">/</span>home<span style="color: #000000; font-weight: bold;">/</span>user<span style="color: #000000; font-weight: bold;">/</span>export.csv</pre></td></tr></table></div>

<p>This command will add a single header line, to the file previously exported, and should end up looking something like below&#8230;</p>
<pre>One,Two,Three,Four,Five
1,2,3,4,5
1,2,3,4,5
1,2,3,4,5</pre>
<p><map name='google_ad_map_911_a45beff5d2e172f6'>
<area shape='rect' href='http://imageads.googleadservices.com/pagead/imgclick/911?pos=0' coords='1,2,367,28' />
<area shape='rect' href='http://services.google.com/feedback/abg' coords='384,10,453,23'/></map>
<img usemap='#google_ad_map_911_a45beff5d2e172f6' border='0' src='http://imageads.googleadservices.com/pagead/ads?format=468x30_aff_img&amp;client=&amp;channel=&amp;output=png&amp;cuid=911&amp;url=http%3A%2F%2Fwww.youdidwhatwithtsql.com%2Fadd-column-headers-mysql-outfile%2F911' title="Add column headers to a MySQL Outfile" alt=" Add column headers to a MySQL Outfile" /></p><p>Post from: <a href="http://www.youdidwhatwithtsql.com">youdidwhatwithtsql.com</a><br/><br/><a href="http://www.youdidwhatwithtsql.com/add-column-headers-mysql-outfile/911">Add column headers to a MySQL Outfile</a></p>
<div class="none"><div class="g-plusone" data-href="http://www.youdidwhatwithtsql.com/add-column-headers-mysql-outfile/911" size="standard" count="true"></div></div>]]></content:encoded>
			<wfw:commentRss>http://www.youdidwhatwithtsql.com/add-column-headers-mysql-outfile/911/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Parse MySQL Slow Logs with mysqlsla</title>
		<link>http://www.youdidwhatwithtsql.com/parse-mysql-slow-logs-with-mysqlsla/856</link>
		<comments>http://www.youdidwhatwithtsql.com/parse-mysql-slow-logs-with-mysqlsla/856#comments</comments>
		<pubDate>Tue, 10 Aug 2010 19:36:21 +0000</pubDate>
		<dc:creator>Rhys</dc:creator>
				<category><![CDATA[DBA]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[Bash]]></category>

		<guid isPermaLink="false">http://www.youdidwhatwithtsql.com/parse-mysql-slow-logs-with-mysqlsla/856</guid>
		<description><![CDATA[Here&#8217;s a bash script that you can use to parse multiple MySQL Slow Query Log files, in one sweep, into something much more understandable. The script uses the handy utility mysqlsla so make sure this is in your path.&#160; mysqlsla parses, filters, analyzes and sorts MySQL slow, general, binary and microslow patched logs in order [...]<p>Post from: <a href="http://www.youdidwhatwithtsql.com">youdidwhatwithtsql.com</a><br/><br/><a href="http://www.youdidwhatwithtsql.com/parse-mysql-slow-logs-with-mysqlsla/856">Parse MySQL Slow Logs with mysqlsla</a></p>
]]></description>
			<content:encoded><![CDATA[<p>Here&#8217;s a bash script that you can use to parse multiple <a title="MySQL Slow Query Logs" href="http://dev.mysql.com/doc/refman/5.1/en/slow-query-log.html" target="_blank">MySQL Slow Query Log</a> files, in one sweep, into something much more understandable. The script uses the handy utility <a href="http://hackmysql.com/mysqlsla" target="_blank">mysqlsla</a> so make sure this is in your path.&nbsp;<br />
<blockquote>mysqlsla parses, filters, analyzes and sorts MySQL <a href="http://dev.mysql.com/doc/refman/5.0/en/slow-query-log.html">slow</a>, <a href="http://dev.mysql.com/doc/refman/5.0/en/query-log.html">general</a>, <a href="http://dev.mysql.com/doc/refman/5.0/en/binary-log.html">binary</a> and <a href="http://www.mysqlperformanceblog.com/2008/04/20/updated-msl-microslow-patch-installation-walk-through/">microslow patched</a> logs in order to create a customizable report of the queries and their meta-property values. Since these reports are customizable, they can be used for human consumption or be fed into other scripts to further analyze the queries. For example, to profile with <a href="http://maatkit.sourceforge.net/doc/mk-query-profiler.html">mk-query-profiler</a> (a script from Baron Schwartz&#8217;s <a href="http://www.maatkit.org/">Maatkit</a>) every unique SELECT statement using database foo from a slow log: <a title="mysqlsla" href="http://hackmysql.com/mysqlsla" target="_blank">source</a></p></blockquote>
<p>Place all your slow logs into a directory. Change the <strong>sl_dir</strong> variable to point at this directory.<strong> </strong>When you execute the script it will create a directory, within your slow logs directory, called reports. This will contain the reports produced by <a title="mysqlsla" href="http://hackmysql.com/mysqlsla" target="_blank">mysqlsla</a>.</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p856code22'); return false;">View Code</a> BASH</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p85622"><td class="code" id="p856code22"><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;"># Script to process multiple mysql slow logs</span>
<span style="color: #666666; font-style: italic;"># using mysqlsla http://hackmysql.com/mysqlsla</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># Directory containing slow logs</span>
<span style="color: #007800;">sl_dir</span>=<span style="color: #ff0000;">&quot;/home/rhys/Desktop/slow_logs&quot;</span>;
&nbsp;
<span style="color: #7a0874; font-weight: bold;">cd</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$sl_dir</span>&quot;</span>;
<span style="color: #666666; font-style: italic;">#slow_logs=$(ls &quot;$sl_dir&quot;);</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># Folder for reports</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: #ff0000;">&quot;<span style="color: #007800;">$sl_dir</span>&quot;</span><span style="color: #000000; font-weight: bold;">/</span>reports <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: #ff0000;">&quot;<span style="color: #007800;">$sl_dir</span>&quot;</span><span style="color: #000000; font-weight: bold;">/</span>reports;
<span style="color: #000000; font-weight: bold;">fi</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># process each slow log file</span>
<span style="color: #000000; font-weight: bold;">for</span> <span style="color: #c20cb9; font-weight: bold;">file</span> <span style="color: #000000; font-weight: bold;">in</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$sl_dir</span>&quot;</span><span style="color: #000000; font-weight: bold;">/*</span>
<span style="color: #000000; font-weight: bold;">do</span>
                <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Processing file: <span style="color: #007800;">$file</span>&quot;</span>;
                <span style="color: #007800;">filename</span>=$<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #c20cb9; font-weight: bold;">basename</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$file</span>&quot;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
                mysqlsla <span style="color: #660033;">-lt</span> slow <span style="color: #ff0000;">&quot;<span style="color: #007800;">$file</span>&quot;</span> <span style="color: #000000; font-weight: bold;">&amp;</span>gt; <span style="color: #ff0000;">&quot;reports/<span style="color: #007800;">$filename</span>.rpt&quot;</span>;
                <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Finished processing file: <span style="color: #007800;">$file</span>&quot;</span>;
<span style="color: #000000; font-weight: bold;">done</span></pre></td></tr></table></div>

<p>The reports produced are much easier to work with than the raw mysql logs so this should be a good time saver when optimising those queries!</p>
<p><map name='google_ad_map_856_a45beff5d2e172f6'>
<area shape='rect' href='http://imageads.googleadservices.com/pagead/imgclick/856?pos=0' coords='1,2,367,28' />
<area shape='rect' href='http://services.google.com/feedback/abg' coords='384,10,453,23'/></map>
<img usemap='#google_ad_map_856_a45beff5d2e172f6' border='0' src='http://imageads.googleadservices.com/pagead/ads?format=468x30_aff_img&amp;client=&amp;channel=&amp;output=png&amp;cuid=856&amp;url=http%3A%2F%2Fwww.youdidwhatwithtsql.com%2Fparse-mysql-slow-logs-with-mysqlsla%2F856' title="Parse MySQL Slow Logs with mysqlsla" alt=" Parse MySQL Slow Logs with mysqlsla" /></p><p>Post from: <a href="http://www.youdidwhatwithtsql.com">youdidwhatwithtsql.com</a><br/><br/><a href="http://www.youdidwhatwithtsql.com/parse-mysql-slow-logs-with-mysqlsla/856">Parse MySQL Slow Logs with mysqlsla</a></p>
<div class="none"><div class="g-plusone" data-href="http://www.youdidwhatwithtsql.com/parse-mysql-slow-logs-with-mysqlsla/856" size="standard" count="true"></div></div>]]></content:encoded>
			<wfw:commentRss>http://www.youdidwhatwithtsql.com/parse-mysql-slow-logs-with-mysqlsla/856/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Can&#8217;t reopen table: &#8216;t1&#8242;</title>
		<link>http://www.youdidwhatwithtsql.com/cant-reopen-table-t1/823</link>
		<comments>http://www.youdidwhatwithtsql.com/cant-reopen-table-t1/823#comments</comments>
		<pubDate>Mon, 19 Jul 2010 21:24:08 +0000</pubDate>
		<dc:creator>Rhys</dc:creator>
				<category><![CDATA[DBA]]></category>
		<category><![CDATA[MySQL]]></category>

		<guid isPermaLink="false">http://www.youdidwhatwithtsql.com/cant-reopen-table-t1/823</guid>
		<description><![CDATA[I&#8217;m quite often jumping between MySQL and SQL Server so remembering the quirks and limitations of each system can be difficult. With MySQL, if you attempt to reference a temporary table more than once in the same query, you will encounter the following error; Error Code : 1137 Can't reopen table: 't1’ The following provides [...]<p>Post from: <a href="http://www.youdidwhatwithtsql.com">youdidwhatwithtsql.com</a><br/><br/><a href="http://www.youdidwhatwithtsql.com/cant-reopen-table-t1/823">Can&#8217;t reopen table: &#8216;t1&#8242;</a></p>
]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m quite often jumping between <a href="http://www.mysql.com" target="_blank">MySQL</a> and <a href="http://www.microsoft.com/en/gb/sqlserver/default.aspx" target="_blank">SQL Server</a> so remembering the quirks and limitations of each system can be difficult. With MySQL, if you attempt to reference a temporary table more than once in the same query, you will encounter the following error;
<pre>Error Code : 1137
Can't reopen table: 't1’</pre>
<p>The following provides an example of this&#8230;</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p823code26'); return false;">View Code</a> MYSQL</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p82326"><td class="code" id="p823code26"><pre class="mysql" style="font-family:monospace;"><span style="color: #990099; font-weight: bold;">USE</span> test<span style="color: #000033;">;</span>
&nbsp;
<span style="color: #990099; font-weight: bold;">CREATE</span> <span style="color: #990099; font-weight: bold;">TEMPORARY</span> <span style="color: #990099; font-weight: bold;">TABLE</span> test
<span style="color: #FF00FF;">&#40;</span>
                Id <span style="color: #999900; font-weight: bold;">INTEGER</span> <span style="color: #CC0099; font-weight: bold;">NOT</span> <span style="color: #9900FF; font-weight: bold;">NULL</span> <span style="color: #FF9900; font-weight: bold;">AUTO_INCREMENT</span> <span style="color: #990099; font-weight: bold;">PRIMARY KEY</span>
<span style="color: #FF00FF;">&#41;</span><span style="color: #000033;">;</span>
&nbsp;
<span style="color: #990099; font-weight: bold;">SELECT</span> <span style="color: #CC0099;">*</span>
<span style="color: #990099; font-weight: bold;">FROM</span> test <span style="color: #990099; font-weight: bold;">AS</span> t1
<span style="color: #990099; font-weight: bold;">INNER</span> <span style="color: #990099; font-weight: bold;">JOIN</span> test <span style="color: #990099; font-weight: bold;">AS</span> t2
     <span style="color: #990099; font-weight: bold;">ON</span> t1.Id <span style="color: #CC0099;">=</span> t2.Id<span style="color: #000033;">;</span></pre></td></tr></table></div>

<p>It&#8217;s not just self-joins that have this issue <strong>UNIONS</strong> do as well;</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p823code27'); return false;">View Code</a> MYSQL</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p82327"><td class="code" id="p823code27"><pre class="mysql" style="font-family:monospace;"><span style="color: #990099; font-weight: bold;">SELECT</span> <span style="color: #CC0099;">*</span>
<span style="color: #990099; font-weight: bold;">FROM</span> test <span style="color: #990099; font-weight: bold;">AS</span> t1
<span style="color: #990099; font-weight: bold;">UNION</span> <span style="color: #990099; font-weight: bold;">ALL</span>
<span style="color: #990099; font-weight: bold;">SELECT</span> <span style="color: #CC0099;">*</span>
<span style="color: #990099; font-weight: bold;">FROM</span> test <span style="color: #990099; font-weight: bold;">AS</span> t2<span style="color: #000033;">;</span></pre></td></tr></table></div>

<p>There&#8217;s a <a href="http://stackoverflow.com/questions/343402/getting-around-mysql-cant-reopen-table-error">thread over on Stackoverflow</a> discussing this problem. Here&#8217;s a solution I commonly use to get around the problem;</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p823code28'); return false;">View Code</a> MYSQL</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p82328"><td class="code" id="p823code28"><pre class="mysql" style="font-family:monospace;"><span style="color: #990099; font-weight: bold;">USE</span> test<span style="color: #000033;">;</span>
&nbsp;
<span style="color: #808080; font-style: italic;"># Create temp table</span>
<span style="color: #990099; font-weight: bold;">CREATE</span> <span style="color: #990099; font-weight: bold;">TEMPORARY</span> <span style="color: #990099; font-weight: bold;">TABLE</span> test
<span style="color: #FF00FF;">&#40;</span>
                Id <span style="color: #999900; font-weight: bold;">INTEGER</span> <span style="color: #CC0099; font-weight: bold;">NOT</span> <span style="color: #9900FF; font-weight: bold;">NULL</span> <span style="color: #FF9900; font-weight: bold;">AUTO_INCREMENT</span> <span style="color: #990099; font-weight: bold;">PRIMARY KEY</span>
<span style="color: #FF00FF;">&#41;</span><span style="color: #000033;">;</span>
&nbsp;
<span style="color: #808080; font-style: italic;"># Insert some test data</span>
<span style="color: #990099; font-weight: bold;">INSERT</span> <span style="color: #990099; font-weight: bold;">INTO</span> test <span style="color: #FF00FF;">&#40;</span>Id<span style="color: #FF00FF;">&#41;</span> <span style="color: #990099; font-weight: bold;">VALUES</span> <span style="color: #FF00FF;">&#40;</span><span style="color: #008080;">1</span><span style="color: #FF00FF;">&#41;</span><span style="color: #000033;">,</span><span style="color: #FF00FF;">&#40;</span><span style="color: #008080;">2</span><span style="color: #FF00FF;">&#41;</span><span style="color: #000033;">,</span><span style="color: #FF00FF;">&#40;</span><span style="color: #008080;">3</span><span style="color: #FF00FF;">&#41;</span><span style="color: #000033;">,</span><span style="color: #FF00FF;">&#40;</span><span style="color: #008080;">4</span><span style="color: #FF00FF;">&#41;</span><span style="color: #000033;">,</span><span style="color: #FF00FF;">&#40;</span><span style="color: #008080;">5</span><span style="color: #FF00FF;">&#41;</span><span style="color: #000033;">;</span>
&nbsp;
<span style="color: #808080; font-style: italic;"># Clone the table. This will do structure &amp; indices but no data.</span>
<span style="color: #990099; font-weight: bold;">CREATE</span> <span style="color: #990099; font-weight: bold;">TEMPORARY</span> <span style="color: #990099; font-weight: bold;">TABLE</span> test2 <span style="color: #CC0099; font-weight: bold;">LIKE</span> test<span style="color: #000033;">;</span>
&nbsp;
<span style="color: #808080; font-style: italic;"># Insert the data into the new table</span>
<span style="color: #990099; font-weight: bold;">INSERT</span> <span style="color: #990099; font-weight: bold;">INTO</span> test2
<span style="color: #990099; font-weight: bold;">SELECT</span> Id
<span style="color: #990099; font-weight: bold;">FROM</span> test<span style="color: #000033;">;</span>
&nbsp;
<span style="color: #808080; font-style: italic;"># Now our queries will work if we use the tables clone</span>
<span style="color: #990099; font-weight: bold;">SELECT</span> <span style="color: #CC0099;">*</span>
<span style="color: #990099; font-weight: bold;">FROM</span> test <span style="color: #990099; font-weight: bold;">AS</span> t1
<span style="color: #990099; font-weight: bold;">INNER</span> <span style="color: #990099; font-weight: bold;">JOIN</span> test2 <span style="color: #990099; font-weight: bold;">AS</span> t2
      <span style="color: #990099; font-weight: bold;">ON</span> t1.Id <span style="color: #CC0099;">=</span> t2.Id<span style="color: #000033;">;</span>
&nbsp;
<span style="color: #990099; font-weight: bold;">SELECT</span> <span style="color: #CC0099;">*</span>
<span style="color: #990099; font-weight: bold;">FROM</span> test <span style="color: #990099; font-weight: bold;">AS</span> t1
<span style="color: #990099; font-weight: bold;">UNION</span> <span style="color: #990099; font-weight: bold;">ALL</span>
<span style="color: #990099; font-weight: bold;">SELECT</span> <span style="color: #CC0099;">*</span>
<span style="color: #990099; font-weight: bold;">FROM</span> test2 <span style="color: #990099; font-weight: bold;">AS</span> t2<span style="color: #000033;">;</span>
&nbsp;
<span style="color: #808080; font-style: italic;"># Clean up</span>
<span style="color: #990099; font-weight: bold;">DROP</span> <span style="color: #990099; font-weight: bold;">TEMPORARY</span> <span style="color: #990099; font-weight: bold;">TABLE</span> <span style="color: #009900;">IF</span> <span style="color: #990099; font-weight: bold;">EXISTS</span> test<span style="color: #000033;">;</span>
<span style="color: #990099; font-weight: bold;">DROP</span> <span style="color: #990099; font-weight: bold;">TEMPORARY</span> <span style="color: #990099; font-weight: bold;">TABLE</span> <span style="color: #009900;">IF</span> <span style="color: #990099; font-weight: bold;">EXISTS</span> test2<span style="color: #000033;">;</span></pre></td></tr></table></div>

<p><map name='google_ad_map_823_a45beff5d2e172f6'>
<area shape='rect' href='http://imageads.googleadservices.com/pagead/imgclick/823?pos=0' coords='1,2,367,28' />
<area shape='rect' href='http://services.google.com/feedback/abg' coords='384,10,453,23'/></map>
<img usemap='#google_ad_map_823_a45beff5d2e172f6' border='0' src='http://imageads.googleadservices.com/pagead/ads?format=468x30_aff_img&amp;client=&amp;channel=&amp;output=png&amp;cuid=823&amp;url=http%3A%2F%2Fwww.youdidwhatwithtsql.com%2Fcant-reopen-table-t1%2F823' title="Cant reopen table: t1" alt=" Cant reopen table: t1" /></p><p>Post from: <a href="http://www.youdidwhatwithtsql.com">youdidwhatwithtsql.com</a><br/><br/><a href="http://www.youdidwhatwithtsql.com/cant-reopen-table-t1/823">Can&#8217;t reopen table: &#8216;t1&#8242;</a></p>
<div class="none"><div class="g-plusone" data-href="http://www.youdidwhatwithtsql.com/cant-reopen-table-t1/823" size="standard" count="true"></div></div>]]></content:encoded>
			<wfw:commentRss>http://www.youdidwhatwithtsql.com/cant-reopen-table-t1/823/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Rename MySQL Stored Procedures</title>
		<link>http://www.youdidwhatwithtsql.com/rename-mysql-stored-procedures/819</link>
		<comments>http://www.youdidwhatwithtsql.com/rename-mysql-stored-procedures/819#comments</comments>
		<pubDate>Wed, 14 Jul 2010 20:47:05 +0000</pubDate>
		<dc:creator>Rhys</dc:creator>
				<category><![CDATA[DBA]]></category>
		<category><![CDATA[MySQL]]></category>

		<guid isPermaLink="false">http://www.youdidwhatwithtsql.com/rename-mysql-stored-procedures/819</guid>
		<description><![CDATA[I’ve previously blogged about the limitations of MySQL Alter Procedure Syntax and I came across a thread on the MySQL forums with a possible solution. I thought it might be handy to wrap this up into a stored procedure akin to SQL Server’s sp_rename. This procedure will allow you to easily rename MySQL Stored Procedures [...]<p>Post from: <a href="http://www.youdidwhatwithtsql.com">youdidwhatwithtsql.com</a><br/><br/><a href="http://www.youdidwhatwithtsql.com/rename-mysql-stored-procedures/819">Rename MySQL Stored Procedures</a></p>
]]></description>
			<content:encoded><![CDATA[<p>I’ve previously blogged about the limitations of <a href="http://www.youdidwhatwithtsql.com/mysql-alter-procedure-syntax/788" target="_blank">MySQL Alter Procedure Syntax</a> and I came across a thread on the <a href="http://forums.mysql.com/read.php?10,274538,274563#msg-274563" target="_blank">MySQL forums</a> with a possible solution. I thought it might be handy to wrap this up into a stored procedure akin to <a href="http://msdn.microsoft.com/en-us/library/ms188351.aspx" target="_blank">SQL Server’s sp_rename</a>. </p>
<p>This procedure will allow you to easily rename MySQL Stored Procedures in any database. Please be aware that this does update the MySQL system tables and has only had minimal testing. As with all tips you find on the Internet please use with caution!</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p819code31'); return false;">View Code</a> MYSQL</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p81931"><td class="code" id="p819code31"><pre class="mysql" style="font-family:monospace;">DELIMITER $$
&nbsp;
<span style="color: #990099; font-weight: bold;">USE</span> <span style="color: #008000;">`mysql`</span>$$
&nbsp;
<span style="color: #990099; font-weight: bold;">DROP</span> <span style="color: #990099; font-weight: bold;">PROCEDURE</span> <span style="color: #009900;">IF</span> <span style="color: #990099; font-weight: bold;">EXISTS</span> <span style="color: #008000;">`mysp<span style="color: #008080; font-weight: bold;">_</span>rename<span style="color: #008080; font-weight: bold;">_</span>proc`</span>$$
&nbsp;
<span style="color: #990099; font-weight: bold;">CREATE</span> <span style="color: #990099; font-weight: bold;">DEFINER</span><span style="color: #CC0099;">=</span><span style="color: #008000;">`root`</span>@<span style="color: #008000;">`<span style="color: #008080; font-weight: bold;">%</span>`</span> <span style="color: #990099; font-weight: bold;">PROCEDURE</span> <span style="color: #008000;">`mysp<span style="color: #008080; font-weight: bold;">_</span>rename<span style="color: #008080; font-weight: bold;">_</span>proc`</span><span style="color: #FF00FF;">&#40;</span><span style="color: #990099; font-weight: bold;">IN</span> p_proc_name <span style="color: #999900; font-weight: bold;">VARCHAR</span><span style="color: #FF00FF;">&#40;</span><span style="color: #008080;">64</span><span style="color: #FF00FF;">&#41;</span><span style="color: #000033;">,</span> <span style="color: #990099; font-weight: bold;">IN</span> p_new_name <span style="color: #999900; font-weight: bold;">VARCHAR</span><span style="color: #FF00FF;">&#40;</span><span style="color: #008080;">64</span><span style="color: #FF00FF;">&#41;</span><span style="color: #000033;">,</span> <span style="color: #990099; font-weight: bold;">IN</span> p_db <span style="color: #999900; font-weight: bold;">VARCHAR</span><span style="color: #FF00FF;">&#40;</span><span style="color: #008080;">64</span><span style="color: #FF00FF;">&#41;</span><span style="color: #FF00FF;">&#41;</span>
    <span style="color: #990099; font-weight: bold;">MODIFIES SQL DATA</span>
    <span style="color: #990099; font-weight: bold;">SQL SECURITY</span> <span style="color: #990099; font-weight: bold;">INVOKER</span>
    <span style="color: #990099; font-weight: bold;">COMMENT</span> <span style="color: #008000;">'Use to rename stored procedures.'</span>
<span style="color: #990099; font-weight: bold;">BEGIN</span>
    proc: <span style="color: #990099; font-weight: bold;">BEGIN</span>
	<span style="color: #808080; font-style: italic;"># A few tests to see if the input is sensible</span>
	<span style="color: #009900;">IF</span> <span style="color: #000099;">CHARACTER_LENGTH</span><span style="color: #FF00FF;">&#40;</span><span style="color: #009900;">IFNULL</span><span style="color: #FF00FF;">&#40;</span>p_proc_name<span style="color: #000033;">,</span> <span style="color: #008000;">''</span><span style="color: #FF00FF;">&#41;</span><span style="color: #FF00FF;">&#41;</span> <span style="color: #CC0099;">=</span> <span style="color: #008080;">0</span> <span style="color: #CC0099; font-weight: bold;">OR</span> <span style="color: #000099;">CHARACTER_LENGTH</span><span style="color: #FF00FF;">&#40;</span><span style="color: #009900;">IFNULL</span><span style="color: #FF00FF;">&#40;</span>p_new_name<span style="color: #000033;">,</span> <span style="color: #008000;">''</span><span style="color: #FF00FF;">&#41;</span><span style="color: #FF00FF;">&#41;</span> <span style="color: #CC0099;">=</span> <span style="color: #008080;">0</span>
		<span style="color: #CC0099; font-weight: bold;">OR</span> <span style="color: #000099;">CHARACTER_LENGTH</span><span style="color: #FF00FF;">&#40;</span><span style="color: #009900;">IFNULL</span><span style="color: #FF00FF;">&#40;</span>p_db<span style="color: #000033;">,</span> <span style="color: #008000;">''</span><span style="color: #FF00FF;">&#41;</span><span style="color: #FF00FF;">&#41;</span> <span style="color: #CC0099;">=</span> <span style="color: #008080;">0</span> <span style="color: #009900;">THEN</span>
	<span style="color: #990099; font-weight: bold;">BEGIN</span>
		<span style="color: #990099; font-weight: bold;">SELECT</span> <span style="color: #008000;">'Error: One of more of the input parameters is zero in length.'</span> <span style="color: #990099; font-weight: bold;">AS</span> Error<span style="color: #000033;">;</span>
		LEAVE proc<span style="color: #000033;">;</span> 
	<span style="color: #009900;">END</span><span style="color: #000033;">;</span>
	ELSEIF <span style="color: #FF00FF;">&#40;</span><span style="color: #990099; font-weight: bold;">SELECT</span> <span style="color: #000099;">COUNT</span><span style="color: #FF00FF;">&#40;</span><span style="color: #CC0099;">*</span><span style="color: #FF00FF;">&#41;</span>
		 <span style="color: #990099; font-weight: bold;">FROM</span> mysql.proc
		 <span style="color: #990099; font-weight: bold;">WHERE</span> <span style="color: #008000;">`name`</span> <span style="color: #CC0099;">=</span> p_proc_name
		 <span style="color: #CC0099; font-weight: bold;">AND</span> <span style="color: #008000;">`type`</span> <span style="color: #CC0099;">=</span> <span style="color: #008000;">'PROCEDURE'</span>
		 <span style="color: #CC0099; font-weight: bold;">AND</span> db <span style="color: #CC0099;">=</span> p_db<span style="color: #FF00FF;">&#41;</span> <span style="color: #CC0099;">=</span> <span style="color: #008080;">0</span> <span style="color: #009900;">THEN</span>
	<span style="color: #990099; font-weight: bold;">BEGIN</span>
		<span style="color: #990099; font-weight: bold;">SELECT</span> <span style="color: #008000;">'Error: The procedure specified in p<span style="color: #008080; font-weight: bold;">_</span>proc<span style="color: #008080; font-weight: bold;">_</span>name does not exist in this database.'</span> <span style="color: #990099; font-weight: bold;">AS</span> Error<span style="color: #000033;">;</span>
		LEAVE proc<span style="color: #000033;">;</span>
	<span style="color: #009900;">END</span><span style="color: #000033;">;</span>
	ELSEIF <span style="color: #FF00FF;">&#40;</span><span style="color: #990099; font-weight: bold;">SELECT</span> <span style="color: #000099;">COUNT</span><span style="color: #FF00FF;">&#40;</span><span style="color: #CC0099;">*</span><span style="color: #FF00FF;">&#41;</span>
		 <span style="color: #990099; font-weight: bold;">FROM</span> mysql.proc
		 <span style="color: #990099; font-weight: bold;">WHERE</span> <span style="color: #008000;">`name`</span> <span style="color: #CC0099;">=</span> p_new_name
		 <span style="color: #CC0099; font-weight: bold;">AND</span> <span style="color: #008000;">`type`</span> <span style="color: #CC0099;">=</span> <span style="color: #008000;">'PROCEDURE'</span>
		 <span style="color: #CC0099; font-weight: bold;">AND</span> db <span style="color: #CC0099;">=</span> p_db<span style="color: #FF00FF;">&#41;</span> <span style="color: #CC0099;">=</span> <span style="color: #008080;">1</span> <span style="color: #009900;">THEN</span>
	<span style="color: #990099; font-weight: bold;">BEGIN</span>
		<span style="color: #990099; font-weight: bold;">SELECT</span> <span style="color: #008000;">'Error: Unable to rename the procedure specified in p<span style="color: #008080; font-weight: bold;">_</span>proc<span style="color: #008080; font-weight: bold;">_</span>name as it already exists in this database.'</span> <span style="color: #990099; font-weight: bold;">AS</span> Error<span style="color: #000033;">;</span>
		LEAVE proc<span style="color: #000033;">;</span>
	<span style="color: #009900;">END</span><span style="color: #000033;">;</span>
	<span style="color: #009900;">END</span> <span style="color: #009900;">IF</span><span style="color: #000033;">;</span>
&nbsp;
	<span style="color: #808080; font-style: italic;"># Rename the proc</span>
	<span style="color: #990099; font-weight: bold;">UPDATE</span> <span style="color: #008000;">`mysql`</span>.<span style="color: #008000;">`proc`</span>
	<span style="color: #990099; font-weight: bold;">SET</span> <span style="color: #008000;">`name`</span> <span style="color: #CC0099;">=</span> p_new_name<span style="color: #000033;">,</span>
	specific_name <span style="color: #CC0099;">=</span> p_new_name
	<span style="color: #990099; font-weight: bold;">WHERE</span> db <span style="color: #CC0099;">=</span> p_db 
	<span style="color: #CC0099; font-weight: bold;">AND</span> <span style="color: #008000;">`name`</span> <span style="color: #CC0099;">=</span> p_proc_name
	<span style="color: #CC0099; font-weight: bold;">AND</span> <span style="color: #008000;">`type`</span> <span style="color: #CC0099;">=</span> <span style="color: #008000;">'PROCEDURE'</span><span style="color: #000033;">;</span>
&nbsp;
	<span style="color: #808080; font-style: italic;"># Update any associated privileges</span>
	<span style="color: #990099; font-weight: bold;">UPDATE</span> <span style="color: #008000;">`mysql`</span>.<span style="color: #008000;">`procs<span style="color: #008080; font-weight: bold;">_</span>priv`</span>
	<span style="color: #990099; font-weight: bold;">SET</span> Routine_name <span style="color: #CC0099;">=</span> p_new_name
	<span style="color: #990099; font-weight: bold;">WHERE</span> db <span style="color: #CC0099;">=</span> p_db 
	<span style="color: #CC0099; font-weight: bold;">AND</span> Routine_name <span style="color: #CC0099;">=</span> p_proc_name
	<span style="color: #CC0099; font-weight: bold;">AND</span> Routine_type <span style="color: #CC0099;">=</span> <span style="color: #008000;">'PROCEDURE'</span><span style="color: #000033;">;</span>
&nbsp;
	<span style="color: #808080; font-style: italic;"># Check update rowcount to see if privileges need to be flushed</span>
	<span style="color: #009900;">IF</span><span style="color: #FF00FF;">&#40;</span><span style="color: #990099; font-weight: bold;">SELECT</span> <span style="color: #000099;">ROW_COUNT</span><span style="color: #FF00FF;">&#40;</span><span style="color: #FF00FF;">&#41;</span><span style="color: #FF00FF;">&#41;</span> <span style="color: #CC0099;">&gt;</span> <span style="color: #008080;">0</span> <span style="color: #009900;">THEN</span>
	<span style="color: #990099; font-weight: bold;">BEGIN</span>
		FLUSH <span style="color: #990099; font-weight: bold;">PRIVILEGES</span><span style="color: #000033;">;</span>
	<span style="color: #009900;">END</span><span style="color: #000033;">;</span>
	<span style="color: #009900;">END</span> <span style="color: #009900;">IF</span><span style="color: #000033;">;</span>
&nbsp;
    <span style="color: #009900;">END</span> proc<span style="color: #000033;">;</span>
    <span style="color: #009900;">END</span>$$
&nbsp;
DELIMITER <span style="color: #000033;">;</span></pre></td></tr></table></div>

<p>Usage is as follows;</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p819code32'); return false;">View Code</a> MYSQL</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p81932"><td class="code" id="p819code32"><pre class="mysql" style="font-family:monospace;"><span style="color: #990099; font-weight: bold;">CALL</span> mysp_rename_proc<span style="color: #FF00FF;">&#40;</span><span style="color: #008000;">'usp<span style="color: #008080; font-weight: bold;">_</span>proc'</span><span style="color: #000033;">,</span> <span style="color: #008000;">'usp<span style="color: #008080; font-weight: bold;">_</span>new<span style="color: #008080; font-weight: bold;">_</span>proc<span style="color: #008080; font-weight: bold;">_</span>name'</span><span style="color: #000033;">,</span> <span style="color: #008000;">'database<span style="color: #008080; font-weight: bold;">_</span>proc<span style="color: #008080; font-weight: bold;">_</span>exists<span style="color: #008080; font-weight: bold;">_</span>in'</span><span style="color: #FF00FF;">&#41;</span><span style="color: #000033;">;</span></pre></td></tr></table></div>

<p>As the thread poster mentions the Stored Procedure is callable by it’s old name as well as the new one until you reconnect. There doesn’t seem to be any suitable <a href="http://dev.mysql.com/doc/refman/5.1/en/flush.html" target="_blank">FLUSH</a> command to resolve this.</p>
<p>If you liked this you may like;</p>
<p><a href="http://www.youdidwhatwithtsql.com/mysql-clone-of-sp_spaceused/636" target="_blank">MySQL Clone of SP_SpaceUsed</a></p>
<p><a href="http://www.youdidwhatwithtsql.com/mysql-clone-of-sp_msforeachtable/624" target="_blank">MySQL Clone of SP_MsForEachTable</a></p>
<p><map name='google_ad_map_819_a45beff5d2e172f6'>
<area shape='rect' href='http://imageads.googleadservices.com/pagead/imgclick/819?pos=0' coords='1,2,367,28' />
<area shape='rect' href='http://services.google.com/feedback/abg' coords='384,10,453,23'/></map>
<img usemap='#google_ad_map_819_a45beff5d2e172f6' border='0' src='http://imageads.googleadservices.com/pagead/ads?format=468x30_aff_img&amp;client=&amp;channel=&amp;output=png&amp;cuid=819&amp;url=http%3A%2F%2Fwww.youdidwhatwithtsql.com%2Frename-mysql-stored-procedures%2F819' title="Rename MySQL Stored Procedures" alt=" Rename MySQL Stored Procedures" /></p><p>Post from: <a href="http://www.youdidwhatwithtsql.com">youdidwhatwithtsql.com</a><br/><br/><a href="http://www.youdidwhatwithtsql.com/rename-mysql-stored-procedures/819">Rename MySQL Stored Procedures</a></p>
<div class="none"><div class="g-plusone" data-href="http://www.youdidwhatwithtsql.com/rename-mysql-stored-procedures/819" size="standard" count="true"></div></div>]]></content:encoded>
			<wfw:commentRss>http://www.youdidwhatwithtsql.com/rename-mysql-stored-procedures/819/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Purge MySQL Binary Logs</title>
		<link>http://www.youdidwhatwithtsql.com/purge-mysql-binary-logs/816</link>
		<comments>http://www.youdidwhatwithtsql.com/purge-mysql-binary-logs/816#comments</comments>
		<pubDate>Mon, 12 Jul 2010 10:58:03 +0000</pubDate>
		<dc:creator>Rhys</dc:creator>
				<category><![CDATA[DBA]]></category>
		<category><![CDATA[MySQL]]></category>

		<guid isPermaLink="false">http://www.youdidwhatwithtsql.com/?p=816</guid>
		<description><![CDATA[From time-to-time you may need to manually purge binary logs on your MySQL slaves to free up a bit of disk space. We can achieve this by using the PURGE BINARY LOGS command from the MySQL command line client. MySQL advises the following procedure when purging these logs To safely purge binary log files, follow [...]<p>Post from: <a href="http://www.youdidwhatwithtsql.com">youdidwhatwithtsql.com</a><br/><br/><a href="http://www.youdidwhatwithtsql.com/purge-mysql-binary-logs/816">Purge MySQL Binary Logs</a></p>
]]></description>
			<content:encoded><![CDATA[<p>From time-to-time you may need to manually purge binary logs on your <a title="MySQL replication" href="http://dev.mysql.com/doc/refman/5.1/en/replication.html" target="_blank">MySQL slaves</a> to free up a bit of disk space. We can achieve this by using the <a title="PURGE BINARY LOGS" href="http://dev.mysql.com/doc/refman/5.5/en/purge-binary-logs.html" target="_blank">PURGE BINARY LOGS command</a> from the MySQL command line client. MySQL advises the following procedure when purging these logs</p>
<blockquote><p>To safely purge binary log files, follow this procedure:</p>
<div>
<ol type="1">
<li>On each slave server, use <a title="12.4.5.35. SHOW SLAVE STATUS Syntax" href="http://dev.mysql.com/doc/refman/5.5/en/show-slave-status.html"><code>SHOW SLAVE             STATUS</code></a> to check which log file it is reading.</li>
<li>Obtain a listing of the binary log files on the master             server with <a title="12.4.5.2. SHOW BINARY LOGS Syntax" href="http://dev.mysql.com/doc/refman/5.5/en/show-binary-logs.html"><code>SHOW BINARY LOGS</code></a>.</li>
<li>Determine the earliest log file among all the slaves. This             is the target file. If all the slaves are up to date, this             is the last log file on the list.</li>
<li>Make a backup of all the log files you are about to delete.             (This step is optional, but always advisable.)</li>
<li>Purge all log files up to but not including the target file. <a title="MySQL purge binary logs" href="http://dev.mysql.com/doc/refman/5.5/en/purge-binary-logs.html" target="_blank">source</a></li>
</ol>
</div>
</blockquote>
<p>The below example will purge all binary logs older than the one called <strong>backup-master.001271</strong>.</p>
<pre>Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2640654
Server version: 5.1.34-log SUSE MySQL RPM

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql&gt; PURGE BINARY LOGS TO 'backup-master.001271'
</pre>
<p>Provided your slave is running this command is reasonably safe as MySQL will prevent you from purging any log files that are currently being read. If the slave thread is not running then you do have to make sure you are not purging a needed file. If you purge a needed file the slave will break when it is restarted. You can also use the <a title="expire_logs_days in my.cnf" href="http://dev.mysql.com/doc/refman/5.0/en/server-system-variables.html#sysvar_expire_logs_days" target="_blank">expire_logs_days</a> variable to automatically control when binary logs are purged.</p>
<p><map name='google_ad_map_816_a45beff5d2e172f6'>
<area shape='rect' href='http://imageads.googleadservices.com/pagead/imgclick/816?pos=0' coords='1,2,367,28' />
<area shape='rect' href='http://services.google.com/feedback/abg' coords='384,10,453,23'/></map>
<img usemap='#google_ad_map_816_a45beff5d2e172f6' border='0' src='http://imageads.googleadservices.com/pagead/ads?format=468x30_aff_img&amp;client=&amp;channel=&amp;output=png&amp;cuid=816&amp;url=http%3A%2F%2Fwww.youdidwhatwithtsql.com%2Fpurge-mysql-binary-logs%2F816' title="Purge MySQL Binary Logs" alt=" Purge MySQL Binary Logs" /></p><p>Post from: <a href="http://www.youdidwhatwithtsql.com">youdidwhatwithtsql.com</a><br/><br/><a href="http://www.youdidwhatwithtsql.com/purge-mysql-binary-logs/816">Purge MySQL Binary Logs</a></p>
<div class="none"><div class="g-plusone" data-href="http://www.youdidwhatwithtsql.com/purge-mysql-binary-logs/816" size="standard" count="true"></div></div>]]></content:encoded>
			<wfw:commentRss>http://www.youdidwhatwithtsql.com/purge-mysql-binary-logs/816/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>For RANGE partitions each partition must be defined</title>
		<link>http://www.youdidwhatwithtsql.com/for-range-partitions-each-partition-must-be-defined/815</link>
		<comments>http://www.youdidwhatwithtsql.com/for-range-partitions-each-partition-must-be-defined/815#comments</comments>
		<pubDate>Fri, 09 Jul 2010 12:08:31 +0000</pubDate>
		<dc:creator>Rhys</dc:creator>
				<category><![CDATA[DBA]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[partition]]></category>
		<category><![CDATA[partitioning]]></category>

		<guid isPermaLink="false">http://www.youdidwhatwithtsql.com/for-range-partitions-each-partition-must-be-defined/815</guid>
		<description><![CDATA[If you encounter the following error when trying to create a partitioned table in MySQL Error Code : 1492 For RANGE partitions each partition must be defined Assuming you have defined your partitions then you probably have a syntax error. Take the following incorrect example. ?View Code MYSQLCREATE TABLE People &#40; PersonId INTEGER NOT NULL [...]<p>Post from: <a href="http://www.youdidwhatwithtsql.com">youdidwhatwithtsql.com</a><br/><br/><a href="http://www.youdidwhatwithtsql.com/for-range-partitions-each-partition-must-be-defined/815">For RANGE partitions each partition must be defined</a></p>
]]></description>
			<content:encoded><![CDATA[<p>If you encounter the following error when trying to create a partitioned table in MySQL</p>
<pre>Error Code : 1492
For RANGE partitions each partition must be defined</pre>
<p>Assuming you have defined your partitions then you probably have a syntax error. Take the following incorrect example.</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p815code35'); return false;">View Code</a> MYSQL</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p81535"><td class="code" id="p815code35"><pre class="mysql" style="font-family:monospace;"><span style="color: #990099; font-weight: bold;">CREATE</span> <span style="color: #990099; font-weight: bold;">TABLE</span> People
<span style="color: #FF00FF;">&#40;</span>
	PersonId <span style="color: #999900; font-weight: bold;">INTEGER</span> <span style="color: #CC0099; font-weight: bold;">NOT</span> <span style="color: #9900FF; font-weight: bold;">NULL</span> <span style="color: #FF9900; font-weight: bold;">AUTO_INCREMENT</span><span style="color: #000033;">,</span>
	FirstName <span style="color: #999900; font-weight: bold;">VARCHAR</span><span style="color: #FF00FF;">&#40;</span><span style="color: #008080;">50</span><span style="color: #FF00FF;">&#41;</span> <span style="color: #CC0099; font-weight: bold;">NOT</span> <span style="color: #9900FF; font-weight: bold;">NULL</span><span style="color: #000033;">,</span>
	LastName <span style="color: #999900; font-weight: bold;">VARCHAR</span><span style="color: #FF00FF;">&#40;</span><span style="color: #008080;">50</span><span style="color: #FF00FF;">&#41;</span> <span style="color: #CC0099; font-weight: bold;">NOT</span> <span style="color: #9900FF; font-weight: bold;">NULL</span><span style="color: #000033;">,</span>
	DateOfBirth <span style="color: #999900; font-weight: bold;">DATE</span> <span style="color: #CC0099; font-weight: bold;">NOT</span> <span style="color: #9900FF; font-weight: bold;">NULL</span><span style="color: #000033;">,</span>
	Telephone <span style="color: #999900; font-weight: bold;">VARCHAR</span><span style="color: #FF00FF;">&#40;</span><span style="color: #008080;">30</span><span style="color: #FF00FF;">&#41;</span> <span style="color: #9900FF; font-weight: bold;">NULL</span><span style="color: #000033;">,</span>
	Email <span style="color: #999900; font-weight: bold;">VARCHAR</span><span style="color: #FF00FF;">&#40;</span><span style="color: #008080;">200</span><span style="color: #FF00FF;">&#41;</span> <span style="color: #9900FF; font-weight: bold;">NULL</span><span style="color: #000033;">,</span>
	GroupId <span style="color: #999900; font-weight: bold;">SMALLINT</span> <span style="color: #CC0099; font-weight: bold;">NOT</span> <span style="color: #9900FF; font-weight: bold;">NULL</span><span style="color: #000033;">,</span>
	<span style="color: #990099; font-weight: bold;">PRIMARY KEY</span> <span style="color: #FF00FF;">&#40;</span>PersonId<span style="color: #000033;">,</span> GroupId<span style="color: #FF00FF;">&#41;</span>
<span style="color: #FF00FF;">&#41;</span>
PARTITION BY RANGE <span style="color: #FF00FF;">&#40;</span>GroupId<span style="color: #FF00FF;">&#41;</span>
PARTITION p0 <span style="color: #990099; font-weight: bold;">VALUES</span> LESS THAN <span style="color: #FF00FF;">&#40;</span><span style="color: #008080;">100</span><span style="color: #FF00FF;">&#41;</span><span style="color: #000033;">,</span>
PARTITION p1 <span style="color: #990099; font-weight: bold;">VALUES</span> LESS THAN <span style="color: #FF00FF;">&#40;</span><span style="color: #008080;">200</span><span style="color: #FF00FF;">&#41;</span><span style="color: #000033;">,</span>
PARTITION p2 <span style="color: #990099; font-weight: bold;">VALUES</span> LESS THAN <span style="color: #FF00FF;">&#40;</span><span style="color: #008080;">300</span><span style="color: #FF00FF;">&#41;</span><span style="color: #000033;">,</span>
PARTITION p3 <span style="color: #990099; font-weight: bold;">VALUES</span> LESS THAN <span style="color: #FF00FF;">&#40;</span><span style="color: #008080;">400</span><span style="color: #FF00FF;">&#41;</span><span style="color: #000033;">,</span>
PARTITION p4 <span style="color: #990099; font-weight: bold;">VALUES</span> LESS THAN <span style="color: #FF00FF;">&#40;</span><span style="color: #008080;">500</span><span style="color: #FF00FF;">&#41;</span><span style="color: #000033;">,</span>
PARTITION p5 <span style="color: #990099; font-weight: bold;">VALUES</span> LESS THAN <span style="color: #FF00FF;">&#40;</span><span style="color: #008080;">600</span><span style="color: #FF00FF;">&#41;</span><span style="color: #000033;">,</span>
PARTITION p6 <span style="color: #990099; font-weight: bold;">VALUES</span> LESS THAN <span style="color: #FF00FF;">&#40;</span><span style="color: #008080;">700</span><span style="color: #FF00FF;">&#41;</span><span style="color: #000033;">;</span></pre></td></tr></table></div>

<p>The above statement is not syntactically correct but the error thrown in this case is not particularly helpful. All that is missing here is a couple of braces around the partition range definitions. The below DDL statement is correct.</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p815code36'); return false;">View Code</a> MYSQL</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p81536"><td class="code" id="p815code36"><pre class="mysql" style="font-family:monospace;"><span style="color: #990099; font-weight: bold;">CREATE</span> <span style="color: #990099; font-weight: bold;">TABLE</span> People
<span style="color: #FF00FF;">&#40;</span>
	PersonId <span style="color: #999900; font-weight: bold;">INTEGER</span> <span style="color: #CC0099; font-weight: bold;">NOT</span> <span style="color: #9900FF; font-weight: bold;">NULL</span> <span style="color: #FF9900; font-weight: bold;">AUTO_INCREMENT</span><span style="color: #000033;">,</span>
	FirstName <span style="color: #999900; font-weight: bold;">VARCHAR</span><span style="color: #FF00FF;">&#40;</span><span style="color: #008080;">50</span><span style="color: #FF00FF;">&#41;</span> <span style="color: #CC0099; font-weight: bold;">NOT</span> <span style="color: #9900FF; font-weight: bold;">NULL</span><span style="color: #000033;">,</span>
	LastName <span style="color: #999900; font-weight: bold;">VARCHAR</span><span style="color: #FF00FF;">&#40;</span><span style="color: #008080;">50</span><span style="color: #FF00FF;">&#41;</span> <span style="color: #CC0099; font-weight: bold;">NOT</span> <span style="color: #9900FF; font-weight: bold;">NULL</span><span style="color: #000033;">,</span>
	DateOfBirth <span style="color: #999900; font-weight: bold;">DATE</span> <span style="color: #CC0099; font-weight: bold;">NOT</span> <span style="color: #9900FF; font-weight: bold;">NULL</span><span style="color: #000033;">,</span>
	Telephone <span style="color: #999900; font-weight: bold;">VARCHAR</span><span style="color: #FF00FF;">&#40;</span><span style="color: #008080;">30</span><span style="color: #FF00FF;">&#41;</span> <span style="color: #9900FF; font-weight: bold;">NULL</span><span style="color: #000033;">,</span>
	Email <span style="color: #999900; font-weight: bold;">VARCHAR</span><span style="color: #FF00FF;">&#40;</span><span style="color: #008080;">200</span><span style="color: #FF00FF;">&#41;</span> <span style="color: #9900FF; font-weight: bold;">NULL</span><span style="color: #000033;">,</span>
	GroupId <span style="color: #999900; font-weight: bold;">SMALLINT</span> <span style="color: #CC0099; font-weight: bold;">NOT</span> <span style="color: #9900FF; font-weight: bold;">NULL</span><span style="color: #000033;">,</span>
	<span style="color: #990099; font-weight: bold;">PRIMARY KEY</span> <span style="color: #FF00FF;">&#40;</span>PersonId<span style="color: #000033;">,</span> GroupId<span style="color: #FF00FF;">&#41;</span>
<span style="color: #FF00FF;">&#41;</span>
PARTITION BY RANGE <span style="color: #FF00FF;">&#40;</span>GroupId<span style="color: #FF00FF;">&#41;</span>
<span style="color: #FF00FF;">&#40;</span>
	PARTITION p0 <span style="color: #990099; font-weight: bold;">VALUES</span> LESS THAN <span style="color: #FF00FF;">&#40;</span><span style="color: #008080;">100</span><span style="color: #FF00FF;">&#41;</span><span style="color: #000033;">,</span>
	PARTITION p1 <span style="color: #990099; font-weight: bold;">VALUES</span> LESS THAN <span style="color: #FF00FF;">&#40;</span><span style="color: #008080;">200</span><span style="color: #FF00FF;">&#41;</span><span style="color: #000033;">,</span>
	PARTITION p2 <span style="color: #990099; font-weight: bold;">VALUES</span> LESS THAN <span style="color: #FF00FF;">&#40;</span><span style="color: #008080;">300</span><span style="color: #FF00FF;">&#41;</span><span style="color: #000033;">,</span>
	PARTITION p3 <span style="color: #990099; font-weight: bold;">VALUES</span> LESS THAN <span style="color: #FF00FF;">&#40;</span><span style="color: #008080;">400</span><span style="color: #FF00FF;">&#41;</span><span style="color: #000033;">,</span>
	PARTITION p4 <span style="color: #990099; font-weight: bold;">VALUES</span> LESS THAN <span style="color: #FF00FF;">&#40;</span><span style="color: #008080;">500</span><span style="color: #FF00FF;">&#41;</span><span style="color: #000033;">,</span>
	PARTITION p5 <span style="color: #990099; font-weight: bold;">VALUES</span> LESS THAN <span style="color: #FF00FF;">&#40;</span><span style="color: #008080;">600</span><span style="color: #FF00FF;">&#41;</span><span style="color: #000033;">,</span>
	PARTITION p6 <span style="color: #990099; font-weight: bold;">VALUES</span> LESS THAN <span style="color: #FF00FF;">&#40;</span><span style="color: #008080;">700</span><span style="color: #FF00FF;">&#41;</span>
<span style="color: #FF00FF;">&#41;</span><span style="color: #000033;">;</span></pre></td></tr></table></div>

<p><map name='google_ad_map_815_a45beff5d2e172f6'>
<area shape='rect' href='http://imageads.googleadservices.com/pagead/imgclick/815?pos=0' coords='1,2,367,28' />
<area shape='rect' href='http://services.google.com/feedback/abg' coords='384,10,453,23'/></map>
<img usemap='#google_ad_map_815_a45beff5d2e172f6' border='0' src='http://imageads.googleadservices.com/pagead/ads?format=468x30_aff_img&amp;client=&amp;channel=&amp;output=png&amp;cuid=815&amp;url=http%3A%2F%2Fwww.youdidwhatwithtsql.com%2Ffor-range-partitions-each-partition-must-be-defined%2F815' title="For RANGE partitions each partition must be defined" alt=" For RANGE partitions each partition must be defined" /></p><p>Post from: <a href="http://www.youdidwhatwithtsql.com">youdidwhatwithtsql.com</a><br/><br/><a href="http://www.youdidwhatwithtsql.com/for-range-partitions-each-partition-must-be-defined/815">For RANGE partitions each partition must be defined</a></p>
<div class="none"><div class="g-plusone" data-href="http://www.youdidwhatwithtsql.com/for-range-partitions-each-partition-must-be-defined/815" size="standard" count="true"></div></div>]]></content:encoded>
			<wfw:commentRss>http://www.youdidwhatwithtsql.com/for-range-partitions-each-partition-must-be-defined/815/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Error dropping database (can&#8217;t rmdir &#8216;./database&#8217;, errno: 39)</title>
		<link>http://www.youdidwhatwithtsql.com/error-dropping-database-cant-rmdir-database-errno-39/801</link>
		<comments>http://www.youdidwhatwithtsql.com/error-dropping-database-cant-rmdir-database-errno-39/801#comments</comments>
		<pubDate>Wed, 23 Jun 2010 21:12:55 +0000</pubDate>
		<dc:creator>Rhys</dc:creator>
				<category><![CDATA[DBA]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[drop database]]></category>

		<guid isPermaLink="false">http://www.youdidwhatwithtsql.com/error-dropping-database-cant-rmdir-database-errno-39/801</guid>
		<description><![CDATA[Just a very quick post today! If you encounter this error when attempting to drop a MySQL database; Error dropping database (can't rmdir './database', errno: 39) Then you probably have some rogue files in the folder where the database files are located. If you cd into this directory you will be able to view these [...]<p>Post from: <a href="http://www.youdidwhatwithtsql.com">youdidwhatwithtsql.com</a><br/><br/><a href="http://www.youdidwhatwithtsql.com/error-dropping-database-cant-rmdir-database-errno-39/801">Error dropping database (can&#8217;t rmdir &#8216;./database&#8217;, errno: 39)</a></p>
]]></description>
			<content:encoded><![CDATA[<p>Just a very quick post today! If you encounter this error when attempting to drop a <a href="http://www.mysql.com" target="_blank">MySQL</a> database;</p>
<pre>Error dropping database (can't rmdir './database', errno: 39)</pre>
<p>Then you probably have some rogue files in the folder where the database files are located. If you <a href="http://www.computerhope.com/unix/ucd.htm" target="_blank">cd</a> into this directory you will be able to view these files. In my case I had a <a href="http://www.gnu.org/software/tar/" target="_blank">tar archive</a> containing the files the database was restored from. Just delete any files in this directory and you’ll be able to complete the drop.</p>
<p><map name='google_ad_map_801_a45beff5d2e172f6'>
<area shape='rect' href='http://imageads.googleadservices.com/pagead/imgclick/801?pos=0' coords='1,2,367,28' />
<area shape='rect' href='http://services.google.com/feedback/abg' coords='384,10,453,23'/></map>
<img usemap='#google_ad_map_801_a45beff5d2e172f6' border='0' src='http://imageads.googleadservices.com/pagead/ads?format=468x30_aff_img&amp;client=&amp;channel=&amp;output=png&amp;cuid=801&amp;url=http%3A%2F%2Fwww.youdidwhatwithtsql.com%2Ferror-dropping-database-cant-rmdir-database-errno-39%2F801' title="Error dropping database (cant rmdir ./database, errno: 39)" alt=" Error dropping database (cant rmdir ./database, errno: 39)" /></p><p>Post from: <a href="http://www.youdidwhatwithtsql.com">youdidwhatwithtsql.com</a><br/><br/><a href="http://www.youdidwhatwithtsql.com/error-dropping-database-cant-rmdir-database-errno-39/801">Error dropping database (can&#8217;t rmdir &#8216;./database&#8217;, errno: 39)</a></p>
<div class="none"><div class="g-plusone" data-href="http://www.youdidwhatwithtsql.com/error-dropping-database-cant-rmdir-database-errno-39/801" size="standard" count="true"></div></div>]]></content:encoded>
			<wfw:commentRss>http://www.youdidwhatwithtsql.com/error-dropping-database-cant-rmdir-database-errno-39/801/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

