<?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>Vance Lucas &#187; MySQL</title>
	<atom:link href="http://www.vancelucas.com/blog/category/mysql/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.vancelucas.com</link>
	<description>Web Entrepreneur and Freelance PHP/Javascript Developer</description>
	<lastBuildDate>Thu, 17 Nov 2011 15:30:33 +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 Error: 1033 Incorrect information in file</title>
		<link>http://www.vancelucas.com/blog/mysql-error-1033-incorrect-information-in-file/</link>
		<comments>http://www.vancelucas.com/blog/mysql-error-1033-incorrect-information-in-file/#comments</comments>
		<pubDate>Wed, 02 Mar 2011 20:52:27 +0000</pubDate>
		<dc:creator>Vance Lucas</dc:creator>
				<category><![CDATA[Database]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[mysql errors]]></category>

		<guid isPermaLink="false">http://www.vancelucas.com/?p=705</guid>
		<description><![CDATA[I recently encountered this error on Disposeamail &#8211; a free disposable email site of mine that uses MySQL heavily for storing all incoming mail through an email pipe script. I did a lot of researching, and basically, there are a few primary culprits I was able to identify that will hopefully save you some time. Check your [...]]]></description>
			<content:encoded><![CDATA[<p>I recently encountered this error on <a href="http://disposeamail.com">Disposeamail</a> &#8211; a free disposable email site of mine that uses MySQL heavily for storing all incoming mail through an email pipe script.</p>
<p>I did a lot of researching, and basically, there are a few primary culprits I was able to identify that will hopefully save you some time.</p>
<p><span id="more-705"></span></p>
<h3>Check your /tmp directory</h3>
<p>MySQL will produce this error sometimes when the temp directory is not writeable.</p>
<ol>
<li>Ensure that <strong>/tmp</strong> (and/or /var/tmp) has the <strong>correct permissions</strong> (777)</li>
<li>Check the <strong>my.cnf </strong>file and search for a <strong>tmpdir</strong>=/tmp flag. Ensure the value is pointing to the correct temp directory.</li>
<li>Ensure your <strong>/tmp directory is not full</strong></li>
</ol>
<h3>Check your my.cnf</h3>
<ol>
<li>If you <strong>made changes</strong> recently, <strong>revert them</strong> and restart MySQL (especially InnoDB Buffer Pool settings)</li>
<li><strong>Restore my.cnf.back</strong> is there is one</li>
<li>If you are using <strong>InnoDB tables</strong>, ensure the <strong>skip-innodb</strong> line in my.cnf is <strong>commented out</strong> or removed.</li>
</ol>
<h3>Clear InnoDB Log Files</h3>
<p>This step <strong>ONLY APPLIES IF THE ABOVE STEPS DID NOT WORK</strong>.</p>
<p>Read the <a href="http://dev.mysql.com/doc/refman/5.0/en/innodb-data-log-reconfiguration.html">MySQL Manual page on removing InnoDB log files</a> for a safer backup and restoration procedures. Basically, the steps are:</p>
<ol>
<li>Shut down MySQL</li>
<li><strong>Remove ib_logfile*</strong> files from the MySQL data directory (move them or rename them if you want to be safe)</li>
<li>Re-start MySQL</li>
</ol>
<p>My specific problem was that somehow the &#8220;skip-innodb&#8221; line got added back into my &#8220;my.cnf&#8221; file, so MySQL was expecting a different table format when loading data. I suspect this had something to do with my cPanel/WHM setup overwriting the file, but I&#8217;ll never know for sure.</p>
<p>Good Luck!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.vancelucas.com/blog/mysql-error-1033-incorrect-information-in-file/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>MySQL Series: How to Detect UTF-8 and Multi-byte Characters</title>
		<link>http://www.vancelucas.com/blog/mysql-series-how-to-detect-utf-8-and-multi-byte-characters/</link>
		<comments>http://www.vancelucas.com/blog/mysql-series-how-to-detect-utf-8-and-multi-byte-characters/#comments</comments>
		<pubDate>Wed, 24 Mar 2010 15:44:39 +0000</pubDate>
		<dc:creator>Vance Lucas</dc:creator>
				<category><![CDATA[Database]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[i18n]]></category>
		<category><![CDATA[sql]]></category>
		<category><![CDATA[utf8]]></category>

		<guid isPermaLink="false">http://www.vancelucas.com/?p=542</guid>
		<description><![CDATA[Multi-byte characters can cause quite a few headaches for the unsuspecting webmaster. Sometimes all you need to do to figure out how to fix the problem is detect which database records have UTF-8 data in them and which ones do not. If you&#8217;ve been scanning records manually, stop now. Here&#8217;s a quick query to cure [...]]]></description>
			<content:encoded><![CDATA[<p>Multi-byte characters can cause quite a few headaches for the unsuspecting webmaster. Sometimes all you need to do to figure out how to fix the problem is detect which database records have UTF-8 data in them and which ones do not. If you&#8217;ve been scanning records manually, stop now. Here&#8217;s a quick query to cure your ales:</p>
<p>Return all the rows with multi-byte characters in table <em>posts</em> on field <em>title</em>:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">SELECT</span> <span style="color: #66cc66;">*</span>
<span style="color: #993333; font-weight: bold;">FROM</span> posts
<span style="color: #993333; font-weight: bold;">WHERE</span> <span style="color: #993333; font-weight: bold;">LENGTH</span><span style="color: #66cc66;">&#40;</span>title<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&lt;&gt;</span> <span style="color: #993333; font-weight: bold;">CHAR_LENGTH</span><span style="color: #66cc66;">&#40;</span>title<span style="color: #66cc66;">&#41;</span></pre></td></tr></table></div>

<p>This does pretty much what it looks like: returns all the rows in the posts table where the title&#8217;s character length does not match the title&#8217;s length. This works because the LENGTH function returns the <em>number of bytes</em> in the string, while the CHAR_LENGTH function returns the <em>number of characters</em> in the string. If the string contains multi-byte characters (individual characters that are made up of more than one byte) like international UTF-8 characters, the two functions will return different numbers and will not be equal, thus including that row in your results.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.vancelucas.com/blog/mysql-series-how-to-detect-utf-8-and-multi-byte-characters/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>MySQL Series: Return NULL Values First With Descending Order</title>
		<link>http://www.vancelucas.com/blog/mysql-series-return-null-values-first-with-descending-order/</link>
		<comments>http://www.vancelucas.com/blog/mysql-series-return-null-values-first-with-descending-order/#comments</comments>
		<pubDate>Wed, 16 Dec 2009 21:28:55 +0000</pubDate>
		<dc:creator>Vance Lucas</dc:creator>
				<category><![CDATA[Database]]></category>
		<category><![CDATA[MySQL]]></category>

		<guid isPermaLink="false">http://www.vancelucas.com/?p=486</guid>
		<description><![CDATA[Sometimes there are unique situations where you need to order query results by a particular field in descending order, but also need NULL values first. The default (and logical) behavior of MySQL in this case is to return NULL values last, because in descending order they have the lowest value (none). But what if you [...]]]></description>
			<content:encoded><![CDATA[<p>Sometimes there are unique situations where you need to order query results by a particular field in descending order, but also need NULL values first. The default (and logical) behavior of MySQL in this case is to return NULL values last, because in descending order they have the lowest value (none). But what if you really need to reverse this and force NULL values to the top of the result set?<br />
<span id="more-486"></span><br />
I recently ran into this situation with movie results. The business requirement was that the movies be displayed in descending order by release date, so that the newest ones appeared first. Okay, pretty simple &#8211; until I looked at the results. Turns out, we had data on movies that were currently in production, but did not yet have a release date set. I accounted for this earlier by allowing the release date column to be NULL in the table schema, but forgot about the ramifications of that on my queries. These movies were obviously newer, but were always displayed last on the results page because of their NULL release dates. Sounds like the perfect scenario for a conditional statement.</p>
<p>Using the <a href="http://dev.mysql.com/doc/refman/5.0/en/control-flow-functions.html">MySQL Control Flow Functions</a>, I quickly crafted an IF() statement in the SELECT portion of the query that looked like this:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="mysql" style="font-family:monospace;"><span style="color: #009900;">IF</span><span style="color: #FF00FF;">&#40;</span>m.date_released <span style="color: #CC0099; font-weight: bold;">IS</span> <span style="color: #9900FF; font-weight: bold;">NULL</span> <span style="color: #CC0099; font-weight: bold;">OR</span> m.date_released <span style="color: #CC0099;">=</span> <span style="color: #008000;">'0000-00-00'</span><span style="color: #000033;">,</span> <span style="color: #008080;">1</span><span style="color: #000033;">,</span> <span style="color: #008080;">0</span><span style="color: #FF00FF;">&#41;</span> <span style="color: #990099; font-weight: bold;">AS</span> in_production</pre></td></tr></table></div>

<p>So if the release date has a NULL value or has been inserted as a blank string and formatted to &#8217;0000-00-00&#8242;, it is given a value of 1, and 0 otherwise. We then sort descending by our new &#8216;in_production&#8217; alias in the ORDER BY clause to get the NULL or empty values on top (assigned a 1 value), and then by release date and other criteria second.</p>
<p>The whole query looks something like this:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code"><pre class="mysql" style="font-family:monospace;"><span style="color: #990099; font-weight: bold;">SELECT</span> m.<span style="color: #CC0099;">*</span><span style="color: #000033;">,</span> <span style="color: #009900;">IF</span><span style="color: #FF00FF;">&#40;</span>m.date_released <span style="color: #CC0099; font-weight: bold;">IS</span> <span style="color: #9900FF; font-weight: bold;">NULL</span> <span style="color: #CC0099; font-weight: bold;">OR</span> m.date_released <span style="color: #CC0099;">=</span> <span style="color: #008000;">'0000-00-00'</span><span style="color: #000033;">,</span> <span style="color: #008080;">1</span><span style="color: #000033;">,</span> <span style="color: #008080;">0</span><span style="color: #FF00FF;">&#41;</span> <span style="color: #990099; font-weight: bold;">AS</span> in_production
<span style="color: #990099; font-weight: bold;">FROM</span> movies <span style="color: #990099; font-weight: bold;">AS</span> m
<span style="color: #990099; font-weight: bold;">ORDER BY</span> in_production <span style="color: #990099; font-weight: bold;">DESC</span><span style="color: #000033;">,</span> m.date_released <span style="color: #990099; font-weight: bold;">DESC</span></pre></td></tr></table></div>

<p>It&#8217;s an easy way to manipulate the result set in MySQL without slowing down the query or issuing multiple queries.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.vancelucas.com/blog/mysql-series-return-null-values-first-with-descending-order/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

