<?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>Chris JeanChris Jean &#187; MySQL</title>
	<atom:link href="http://chrisjean.com/tag/mysql/feed/" rel="self" type="application/rss+xml" />
	<link>http://chrisjean.com</link>
	<description>Linux, WordPress, programming, anime, and other stuff</description>
	<lastBuildDate>Mon, 16 Jan 2012 15:22:13 +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>Fix PHP 4 &#8220;Client does not support authentication protocol requested by server&#8221;</title>
		<link>http://chrisjean.com/2010/05/25/fix-php-4-client-does-not-support-authentication-protocol/</link>
		<comments>http://chrisjean.com/2010/05/25/fix-php-4-client-does-not-support-authentication-protocol/#comments</comments>
		<pubDate>Tue, 25 May 2010 20:25:44 +0000</pubDate>
		<dc:creator>Chris Jean</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://gaarai.com/?p=1774</guid>
		<description><![CDATA[I&#8217;m working on building an ideal server setup that allows for both PHP 4 and PHP 5 on Apache with suPHP (I&#8217;ll blog about this later). While testing my PHP 4 build, I got the following error: Warning: mysql_connect() [function.mysql-connect]: Client does not support authentication protocol requested by server; consider upgrading MySQL client in /var/www/test-php.php [...]]]></description>
			<content:encoded><![CDATA[<!-- filtered -->
<p>I&#8217;m working on building an ideal server setup that allows for both <a href="http://php.net/">PHP</a> 4 and PHP 5 on <a href="http://www.apache.org/">Apache</a> with <a href="http://www.suphp.org/Home.html">suPHP</a> (I&#8217;ll blog about this later). While testing my PHP 4 build, I got the following error:</p>
<p style="padding-left: 30px;">Warning: mysql_connect() [function.mysql-connect]: Client does not support authentication protocol requested by server; consider upgrading MySQL client in /var/www/test-php.php  on line 3<br />
Couldn&#8217;t authenticate with MySQL</p>
<p>The code I used to test this is quite simple:</p>
<pre>&lt;?php

if ( false === ( $db = mysql_connect( 'localhost', 'username', 'password' ) ) )
    die( "Couldn't authenticate with MySQL" );

if ( false === mysql_select_db( 'database' ) )
    die( "Couldn't connect to database" );

echo "Yay!";

?&gt;</pre>
<p>After digging around for a bit, I found that mixing PHP 4 with a MySQL version greater than or equal to 4.1 causes this problem. MySQL 4.1 introduced a new password caching scheme that PHP 4 can&#8217;t work with.</p>
<p>The solution is to update the database user&#8217;s password using the OLD_PASSWORD function of MySQL. For example:</p>
<pre class="terminal"><span style="color:#8FED99;">[<span style="color:#BBFF33;">chris@office</span> <span style="color:#729FCF;">~</span>]$</span> <span style="color:#FFF;">mysql -u root -p mysql</span>
Enter password:
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 267
Server version: 5.1.41-3ubuntu12.1 (Ubuntu)

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

<span style="color:#8FED99;">mysql&gt;</span> <span style="color:#FFF;">update user set Password=OLD_PASSWORD('<span style="text-decoration: underline;">password</span>') WHERE User='<span style="text-decoration: underline;">username</span>';</span>
Query OK, 0 rows affected (0.02 sec)
Rows matched: 0  Changed: 0  Warnings: 0

<span style="color:#8FED99;">mysql&gt;</span> <span style="color:#FFF;">flush privileges;</span>
Query OK, 0 rows affected (0.00 sec)

<span style="color:#8FED99;">mysql&gt;</span></pre>
<p>Note the underlined areas. That is where you&#8217;ll want to provide your own username and password.</p>
<p>Once you&#8217;ve followed these steps, both PHP 4 and PHP 5 will be able to communite with the database.</p>
<p>Thanks to <a href="http://www.digitalpeer.com/id/mysql">digitalpeer</a> for providing the answer to my issue.</p>
]]></content:encoded>
			<wfw:commentRss>http://chrisjean.com/2010/05/25/fix-php-4-client-does-not-support-authentication-protocol/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>MySQL ERROR 1018: Unable to Follow Symlink in Ubuntu</title>
		<link>http://chrisjean.com/2010/05/21/mysql-error-1018-unable-to-follow-symlink-in-ubuntu/</link>
		<comments>http://chrisjean.com/2010/05/21/mysql-error-1018-unable-to-follow-symlink-in-ubuntu/#comments</comments>
		<pubDate>Fri, 21 May 2010 17:40:31 +0000</pubDate>
		<dc:creator>Chris Jean</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Tips 'n Tricks]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[symlink]]></category>
		<category><![CDATA[Ubuntu]]></category>

		<guid isPermaLink="false">http://gaarai.com/?p=1764</guid>
		<description><![CDATA[I recently had a issue getting MySQL to read a specific database. Each time I tried to manually query a table in the database, I received the following error message: ERROR 1018 (HY000): Can't read dir of './default/' (errno: 13) I&#8217;ve seen this message before as it means that there is a permissions issue. I [...]]]></description>
			<content:encoded><![CDATA[<!-- filtered -->
<p>I recently had a issue getting MySQL to read a specific database. Each time I tried to manually query a table in the database, I received the following error message:</p>
<pre>ERROR 1018 (HY000): Can't read dir of './default/' (errno: 13)</pre>
<p>I&#8217;ve seen this message before as it means that there is a permissions issue. I checked the ownerships and permissions, and everything seemed to be in order.</p>
<p>The only thing special about this database is that I have it symlinked to another partition. This has always worked in the past, so I was stumped.</p>
<p>The problem turned out to be that Ubuntu has <a href="http://en.wikipedia.org/wiki/AppArmor">AppArmor</a>. This software sets up rules that prevent software from gaining access to different areas of the file system. In my case, AppArmor was preventing read and write access to the actual location of my database files.</p>
<p>The solution was quite easy: First, I added the path that I wanted MySQL to have access to in the AppArmor configuration file for MySQL. Second, I restarted the apparmor service. Here&#8217;s the technical details:</p>
<ol>
<li>On my system, the configuration file that controls MySQL permissions through AppArmor are located at /etc/apparmor.d/usr.sbin.mysqld. The following shows the contents of the file as it now exists:
<pre># vim:syntax=apparmor
# Last Modified: Tue Jun 19 17:37:30 2007
#include 

/usr/sbin/mysqld {
  #include
  #include
  #include
  #include
  #include 

  capability dac_override,
  capability sys_resource,
  capability setgid,
  capability setuid,

  network tcp,

  /etc/hosts.allow r,
  /etc/hosts.deny r,

  /etc/mysql/*.pem r,
  /etc/mysql/conf.d/ r,
  /etc/mysql/conf.d/* r,
  /etc/mysql/my.cnf r,
  /usr/sbin/mysqld mr,
  /usr/share/mysql/** r,
  /var/log/mysql.log rw,
  /var/log/mysql.err rw,
  /var/lib/mysql/ r,
  /var/lib/mysql/** rwk,
  /var/log/mysql/ r,
  /var/log/mysql/* rw,
  /var/run/mysqld/mysqld.pid w,
  /var/run/mysqld/mysqld.sock w,
  <strong>/home/sites/default/mysql/ rw,
  /home/sites/default/mysql/* rw,</strong>

  /sys/devices/system/cpu/ r,
}</pre>
<p>The two lines in bold show what I added to the configuation. The first line gives read and write access to the directory itself while the second gives read and write access to the files contained in the directory.</li>
<li>After saving the configuration changes, I simply needed to restart the AppArmor daemon. I did this with the following command:
<pre class="terminal"><span style="color:#8FED99;">[<span style="color:#BBFF33;">chris@rommie</span> <span style="color:#729FCF;">~</span>]$</span> <span style="color:#FFF;">sudo service apparmor restart</span>
 * Reloading AppArmor profiles
Skipping profile in /etc/apparmor.d/disable: usr.bin.firefox</pre>
</li>
</ol>
]]></content:encoded>
			<wfw:commentRss>http://chrisjean.com/2010/05/21/mysql-error-1018-unable-to-follow-symlink-in-ubuntu/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>MySQL Natural Sort Order By on Non-Numeric Field Type</title>
		<link>http://chrisjean.com/2009/04/19/mysql-natural-sort-order-by-on-non-numeric-field-type/</link>
		<comments>http://chrisjean.com/2009/04/19/mysql-natural-sort-order-by-on-non-numeric-field-type/#comments</comments>
		<pubDate>Sun, 19 Apr 2009 05:00:45 +0000</pubDate>
		<dc:creator>Chris Jean</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Tips 'n Tricks]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[Tips]]></category>

		<guid isPermaLink="false">http://gaarai.com/?p=1408</guid>
		<description><![CDATA[I recently worked on a project where I had to sort a set of rows returned from a MySQL query. The problem is that most of the data in the field being sorted is numeric yet the field type is varchar since some of the entries contained characters. The reason that this is a problem [...]]]></description>
			<content:encoded><![CDATA[<!-- filtered -->
<p>I recently worked on a project where I had to sort a set of rows returned from a MySQL query. The problem is that most of the data in the field being sorted is numeric yet the field type is varchar since some of the entries contained characters.</p>
<p>The reason that this is a problem is that MySQL sorts character fields using a method that will produce undesirable results with numeric data. For example, sorting 4, 10, and 50 as character data produces 10, 4, and 50. In most applications, this is highly undesirable.</p>
<p>The solution to this is to force a sorting order that is commonly referred to as a natural sort. Natural sort is just a term that refers to how humans would commonly sort a set of information (numbers as numbers and non-numeric characters alphabetically). Fortunately, this isn&#8217;t difficult to achieve in MySQL.</p>
<p><span id="more-1408"></span>To further illustrate the problem, here is a simple table description:</p>
<pre>&gt; DESC SampleData;
<table border="0">
<tbody>
<tr>
<th><b>Field</b></th>
<th><b>Type</b></th>
</tr>
<tr>
<td>data_char&nbsp;</td>
<td>varchar(5)</td>
</tr>
</tbody>
</table>
</pre>
<p>I filled up the table with sample data. The following example query and resulting data shows the problem clearly:</p>
<pre>&gt; SELECT * FROM SampleData ORDER BY data_char;
<table border="0">
<tbody>
<tr>
<th><b>data_char</b></th>
</tr>
<tr>
<td>10</td>
</tr>
<tr>
<td>11</td>
</tr>
<tr>
<td>120</td>
</tr>
<tr>
<td>21</td>
</tr>
<tr>
<td>3</td>
</tr>
<tr>
<td>a1</td>
</tr>
</tbody>
</table>
</pre>
<p>As you can see, the results aren&#8217;t exactly usable. If we simply modify the order by declaration slightly (add &#8220;+0&#8243; to the order by field), you can force MySQL to sort the field naturally.</p>
<pre>&gt; SELECT * FROM SampleData ORDER BY data_char+0;
<table border="0">
<tbody>
<tr>
<th><b>data_char</b></th>
</tr>
<tr>
<td>3</td>
</tr>
<tr>
<td>10</td>
</tr>
<tr>
<td>11</td>
</tr>
<tr>
<td>21</td>
</tr>
<tr>
<td>120</td>
</tr>
<tr>
<td>a1</td>
</tr>
</tbody>
</table>
</pre>
<p>There you have it. To force a natural sort, just add a 0 onto the field you wish to be naturally sorted.</p>
]]></content:encoded>
			<wfw:commentRss>http://chrisjean.com/2009/04/19/mysql-natural-sort-order-by-on-non-numeric-field-type/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Tool to Optimize MySQL Configuration and Performance</title>
		<link>http://chrisjean.com/2008/10/23/optimize-mysql-configuration-and-performance/</link>
		<comments>http://chrisjean.com/2008/10/23/optimize-mysql-configuration-and-performance/#comments</comments>
		<pubDate>Thu, 23 Oct 2008 16:21:03 +0000</pubDate>
		<dc:creator>Chris Jean</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Tips 'n Tricks]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[Tips]]></category>
		<category><![CDATA[Tools]]></category>

		<guid isPermaLink="false">http://gaarai.com/?p=367</guid>
		<description><![CDATA[Web applications developers such as myself often have a hard time keeping up with everything that&#8217;s going on. There&#8217;s always some new programming or scripting language, new standards, new browsers, new technologies, new paradigms, new social networks, and on and on. Every day, something new happens. The end result of all of this always ends [...]]]></description>
			<content:encoded><![CDATA[<!-- filtered -->
<p>Web applications developers such as myself often have a hard time keeping up with everything that&#8217;s going on. There&#8217;s always some new programming or scripting language, new standards, new browsers, new technologies, new paradigms, new social networks, and on and on. Every day, something new happens. The end result of all of this always ends up being very similar: people demand faster applications that deal with ever-increasing amounts of data which end up putting massive stress on the server architecture.</p>
<p>As we toil to improve the performance of the applications and their snappy response times, it becomes easy to forget about how we can tweak settings on a low level to provide massive speed improvements on the front-end. For example, most people don&#8217;t know that you can configure MySQL to take better advantage of the resources that the server has available.</p>
<p>By default, MySQL is configured to consume a relatively limited amount of memory resources. Start giving MySQL more memory to work with, and your application&#8217;s performance can improve greatly.</p>
<p><span id="more-367"></span></p>
<p>Unfortunately, I&#8217;m not a MySQL configuration guru. I&#8217;ve never read through the source code or any low-level technical documents about how it functions. So most of the configurations options are a complete mystery to me, and I don&#8217;t know if changing a specific option could benefit me at all.</p>
<p>Fortunately, I don&#8217;t have to be a MySQL configuration guru to get better performance. There is an amazing tool created by Matthew Montgomery called the <a href="http://day32.com/MySQL/" target="_blank">MySQL performance tuning primer script</a>.</p>
<p>Matthew Montgomery&#8217;s script does an amazing job of giving me information about how my MySQL configuration may be inappropriate for the queries being executed and provides information about what variables to modify in order to better optimize my configuration. For example, the &#8220;TEMP TABLES&#8221; section of the output tells me the following:</p>
<pre style="padding-left: 30px;">TEMP TABLES
Current max_heap_table_size = 512 M
Current tmp_table_size = 512 M
Of 1684 temp tables, 10% were created on disk
Effective in-memory tmp_table_size is limited to max_heap_table_size.
Created disk tmp tables ratio seems fine</pre>
<p>Previously, I had my <code>max_heap_table_size</code> and <code>tmp_table_size</code> variables set to default settings and had up to 60% of my temp tables created on disk. As much as possible, temp tables should be created in memory to reduce the performance penalty of using the disk for random access to such data rather than memory which is much faster.</p>
<p>Now this doesn&#8217;t mean that you should set your variables to the same settings as I have. The server that this is running on is dedicated to running a dispatching system that has many tables containing hundreds of thousands of rows each. The value of the script is that it will help you tailor your settings to best use your hardware without having MySQL consume too many resources that other processes (such as you web server) could use.</p>
<p>The script is provided as a standard Linux shell script. <a href="http://day32.com/MySQL/tuning-primer.sh" target="_blank">Download the script</a> into a folder of your choosing and run &#8220;<code>sh tuning-primer.sh</code>&#8220;.</p>
<p>Good luck with your MySQL optimization. I hope that you get as great of results as I have. Keep in mind that if your table structures and queries are inefficient to begin with, that configuration optimization can only do so much to improve the performance.</p>
<h2>Further Reading</h2>
<ul>
<li><a href="http://www.ibm.com/developerworks/library/l-tune-lamp-3.html" target="_blank">Tuning LAMP systems, Part 3: Tuning your MySQL server</a><br />
This is a great read that should help most novice database administrators understand some of the basics about tuning their database&#8217;s performance.</li>
<li><a href="http://www.mysqlperformanceblog.com/" target="_blank">MySQL Performance Blog</a><br />
A blog by the authors of <a href="http://oreilly.com/catalog/9780596101718/" target="_blank">High Performance MySQL</a> (also highly recommended). This blog is updated frequently with great tips that will help you develop higher-performance apps.</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://chrisjean.com/2008/10/23/optimize-mysql-configuration-and-performance/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

