<?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>Prodromus &#187; Errors</title>
	<atom:link href="http://www.prodromus.com/category/mysql/errors/feed" rel="self" type="application/rss+xml" />
	<link>http://www.prodromus.com</link>
	<description>A forerunner to the future...</description>
	<lastBuildDate>Thu, 19 Jan 2012 22:32:37 +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 &#8211; ORDER BY does not sort data properly&#8230;</title>
		<link>http://www.prodromus.com/2010/12/28/mysql-order-by-does-not-sort-data-properly</link>
		<comments>http://www.prodromus.com/2010/12/28/mysql-order-by-does-not-sort-data-properly#comments</comments>
		<pubDate>Tue, 28 Dec 2010 22:24:16 +0000</pubDate>
		<dc:creator>Prodromus</dc:creator>
				<category><![CDATA[Errors]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[Optimization]]></category>
		<category><![CDATA[Enigma]]></category>
		<category><![CDATA[enum]]></category>
		<category><![CDATA[ORDER]]></category>
		<category><![CDATA[order by]]></category>
		<category><![CDATA[query]]></category>
		<category><![CDATA[Select]]></category>
		<category><![CDATA[simple queries]]></category>
		<category><![CDATA[sort]]></category>
		<category><![CDATA[sort broken]]></category>
		<category><![CDATA[table structure]]></category>
		<category><![CDATA[undiscovered]]></category>

		<guid isPermaLink="false">http://www.prodromus.com/?p=408</guid>
		<description><![CDATA[Imagine a developer working late at night trying to complete some simple queries for a report due the next day.  No matter what she does, the resulting query will just not sort properly. Is this some undiscovered MySQL bug?  No wonder this software is free, MySQL is broke and can&#8217;t even perform a basic sort. [...]]]></description>
			<content:encoded><![CDATA[<p>Imagine a developer working late at night trying to complete some simple queries for a report due the next day.  No matter what she does, the resulting query will just not sort properly. Is this some undiscovered MySQL bug?  No wonder this software is free, MySQL is broke and can&#8217;t even perform a basic sort.  It looks simple, sort the data in a table:</p>
<p>mysql&gt; SELECT id, technology from Enigma;<br />
+&#8212;&#8212;+&#8212;&#8212;&#8212;&#8212;-+<br />
| Id | technology |<br />
+&#8212;&#8212;+&#8212;&#8212;&#8212;&#8212;-+<br />
| 1 | PHP |<br />
| 2 | LINUX |<br />
| 3 | MySQL |<br />
+&#8212;&#8212;+&#8212;&#8212;&#8212;&#8212;-+</p>
<p>To sort the records based on the technology, do an ORDER BY on column Technology:</p>
<p>mysql&gt; SELECT id, technology from Enigma ORDER BY Technology;<br />
+&#8212;&#8212;+&#8212;&#8212;&#8212;&#8212;-+<br />
| Id | technology |<br />
+&#8212;&#8212;+&#8212;&#8212;&#8212;&#8212;-+<br />
| 1 | PHP |<br />
| 2 | LINUX |<br />
| 3 | MySQL |<br />
+&#8212;&#8212;+&#8212;&#8212;&#8212;&#8212;-+</p>
<p>It seems that the server does not understand what I have asked, or I have not mastered the entire alphabet &#8230;<br />
Let&#8217;s add the clause CSA (just in case!)</p>
<p>mysql&gt; SELECT id, technology from Enigma ORDER BY ASC Technology;<br />
+&#8212;&#8212;+&#8212;&#8212;&#8212;&#8212;-+<br />
| Id | technology |<br />
+&#8212;&#8212;+&#8212;&#8212;&#8212;&#8212;-+<br />
| 1 | PHP |<br />
| 2 | LINUX |<br />
| 3 | MySQL |<br />
+&#8212;&#8212;+&#8212;&#8212;&#8212;&#8212;-+</p>
<p>That does not seem to be any better!  MySQL does not sort the data as I wish, am I going crazy? Should I change my RDBMS?<br />
Don&#8217;t worry, a careful look at the table structure allows us to see things clearly.</p>
<p>mysql&gt; SHOW CREATE TABLE enigma;</p>
<p>Table: enigma<br />
Create Table: CREATE TABLE `Enigma` (<br />
`Id` int (11) DEFAULT NULL,<br />
`Technology` enum (&#8216;PHP&#8217;, &#8216;Linux&#8217;, &#8216;MySQL&#8217;) DEFAULT NULL<br />
) ENGINE = MyISAM DEFAULT CHARSET = latin1</p>
<p>The column technology is of a type ENUM.  The Enum field is stored as an integer, and that is the index that MySQL uses for sorting.  In other words, 1 is PHP, 3 is MySQL, and 2 is Linux, so sorting does works properly, just not as expected when the Enum data field is storing character data.  So how do you get the desired result?  Simply force MySQL to use the value string and not index when sorting.   This can be done by using either the Concat() or Cast() functions, as follows:</p>
<p>function concat ()<br />
mysql&gt; SELECT id, technology from Enigma ORDER BY concat (technology);<br />
+&#8212;&#8212;+&#8212;&#8212;&#8212;&#8212;-+<br />
| Id | technology |<br />
+&#8212;&#8212;+&#8212;&#8212;&#8212;&#8212;-+<br />
| 2 | LINUX |<br />
| 3 | MySQL |<br />
| 1 | PHP |<br />
+&#8212;&#8212;+&#8212;&#8212;&#8212;&#8212;-+<br />
function cast ()<br />
mysql&gt; SELECT id, technology from Enigma ORDER BY cast (technology as char);<br />
<span style="font-size: 11.6667px;">+&#8212;&#8212;+&#8212;&#8212;&#8212;&#8212;-+<br />
| id | Technology |<br />
+&#8212;&#8211; -+&#8212;&#8212;&#8212;&#8212;-+<br />
| 2 | LINUX |<br />
| 3 | MySQL |<br />
| 1 | PHP |<br />
+&#8212;&#8212;+&#8212;&#8212;&#8212;&#8211; &#8211; +</span></p>
]]></content:encoded>
			<wfw:commentRss>http://www.prodromus.com/2010/12/28/mysql-order-by-does-not-sort-data-properly/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>MySQL &#8211; Help, I lost the Root password!  Error number 1045</title>
		<link>http://www.prodromus.com/2010/09/07/mysql-help-i-lost-the-root-password-error-number-1045</link>
		<comments>http://www.prodromus.com/2010/09/07/mysql-help-i-lost-the-root-password-error-number-1045#comments</comments>
		<pubDate>Tue, 07 Sep 2010 19:11:13 +0000</pubDate>
		<dc:creator>Prodromus</dc:creator>
				<category><![CDATA[Errors]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[FLUSH]]></category>
		<category><![CDATA[mysql error number 1045]]></category>
		<category><![CDATA[mysql server]]></category>
		<category><![CDATA[password]]></category>
		<category><![CDATA[PRIVILEGES]]></category>
		<category><![CDATA[root]]></category>
		<category><![CDATA[root password]]></category>
		<category><![CDATA[server]]></category>

		<guid isPermaLink="false">http://www.prodromus.com/?p=347</guid>
		<description><![CDATA[Have you ever seen the dreaded MySQL Error number 1045 Access denied for user &#8216;root&#8217;@'localhost&#8217; (using password: YES)? Don&#8217;t worry, this is an easy to recover from situation. Just follow these basic steps to reset the root user password. Stop the MySQL server process. Start the MySQL server process with the &#8211;skip-grant-tables option. This option [...]]]></description>
			<content:encoded><![CDATA[<p>Have you ever seen the dreaded MySQL Error number 1045 Access denied for user &#8216;root&#8217;@'localhost&#8217; (using password: YES)?</p>
<p>Don&#8217;t worry, this is an easy to recover from situation.  Just follow these basic steps to reset the root user password.</p>
<p>Stop the MySQL server process.</p>
<p>Start the MySQL server process with the &#8211;skip-grant-tables option.  This option causes the server to start without using the privilege system at all, which gives <strong>anyone </strong>with access to the server unrestricted access to all databases. BEWARE!  Anyone can access your server, so make sure off the Internet, and that you perform the following steps as quickly as possible.</p>
<p>Start the MySQL console client with the -u root option.  Mysql -u root</p>
<p>SELECT * FROM mysql.user;</p>
<p>UPDATE mysql.user SET Password=PASSWORD(&#8216;[password]&#8216;) WHERE User=&#8217;[username]&#8216;;  Replace [username] with root to change root.  You can also change any other user as well.</p>
<p>Stop the MySQL process</p>
<p>Start the MySQL Process normally (i.e. without the &#8211;skip-grant-tables option).</p>
<p>Some folks have reported that issuing a Flush Privileges command will prevent your having to perform the final Stop/Start of the MySQL server.  However, this has not always worked for me, and I think to be safe, it is wise to recycle the server.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.prodromus.com/2010/09/07/mysql-help-i-lost-the-root-password-error-number-1045/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>MySQL &#8211; ERROR 1005: Can&#8217;t create table (errno: 150) &#8211; INNODB</title>
		<link>http://www.prodromus.com/2010/05/13/mysql-error-1005-cant-create-table-errno-150-innodb</link>
		<comments>http://www.prodromus.com/2010/05/13/mysql-error-1005-cant-create-table-errno-150-innodb#comments</comments>
		<pubDate>Thu, 13 May 2010 17:19:14 +0000</pubDate>
		<dc:creator>Prodromus</dc:creator>
				<category><![CDATA[Errors]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[ALTER]]></category>
		<category><![CDATA[CHARSET]]></category>
		<category><![CDATA[COLLATE]]></category>
		<category><![CDATA[Foreign]]></category>
		<category><![CDATA[foreign key]]></category>
		<category><![CDATA[incompatibility]]></category>
		<category><![CDATA[Innodb]]></category>
		<category><![CDATA[integer]]></category>
		<category><![CDATA[key]]></category>
		<category><![CDATA[table]]></category>
		<category><![CDATA[UNSIGNED]]></category>
		<category><![CDATA[unsigned integer]]></category>

		<guid isPermaLink="false">http://www.prodromus.com/?p=276</guid>
		<description><![CDATA[If you have seen this error, don&#8217;t worry, you are not alone. This error is often accompanied by a message that a table or file could not be created, and usually happens when creating a foreign key. In my experience, 99% of the time this is due to an incompatibility between the two fields in [...]]]></description>
			<content:encoded><![CDATA[<p>If you have seen this error, don&#8217;t worry, you are not alone.  This error is often accompanied by a message that a table or file could not be created, and usually happens when creating a foreign key.  In my experience, 99% of the time this is due to an incompatibility between the two fields in the foreign key.  Usually it is something simple like unsigned integer to signed integer.  The trickiest I have seen is when trying to create a foreign key between two CHAR fields and they do not share the same CHARSET and COLLATE.  ALTER the table so that the CHARSET and COLLATE are the same, and try to add the foreign key again.  </p>
<p>Let me know if you have other examples of how you have worked around errno: 150 when adding foreign keys.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.prodromus.com/2010/05/13/mysql-error-1005-cant-create-table-errno-150-innodb/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

