<?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>Managed Chaos &#187; Database</title>
	<atom:link href="http://blogs.agilefaqs.com/category/database/feed/" rel="self" type="application/rss+xml" />
	<link>http://blogs.agilefaqs.com</link>
	<description>Naresh Jain&#039;s Random Thoughts on Software Development and Adventure Sports</description>
	<lastBuildDate>Sat, 21 Jan 2012 11:54:57 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=</generator>
		<item>
		<title>Trailing White Spaces are Ignored by MySQL for Comparison in a Select Statement</title>
		<link>http://blogs.agilefaqs.com/2011/06/22/trailing-white-spaces-are-ignored-by-mysql-for-comparison-in-a-select-statement/</link>
		<comments>http://blogs.agilefaqs.com/2011/06/22/trailing-white-spaces-are-ignored-by-mysql-for-comparison-in-a-select-statement/#comments</comments>
		<pubDate>Wed, 22 Jun 2011 07:30:48 +0000</pubDate>
		<dc:creator>Naresh Jain</dc:creator>
				<category><![CDATA[Database]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[unique constraint]]></category>
		<category><![CDATA[varchar]]></category>
		<category><![CDATA[whitespaces]]></category>

		<guid isPermaLink="false">http://blogs.agilefaqs.com/?p=1736</guid>
		<description><![CDATA[Just learned today that for char or varchar columns, MySQL ignores trailing white spaces for comparison in a select statement&#8217;s where clause. This came as a surprise because I was thinking that the string &#8216;naresh@industriallogic.com&#8217; is different from &#8216;naresh@industriallogic.com &#8216;. mysql&#62; CREATE TABLE `mysql_trailing_test` &#40; `id` BIGINT&#40;20&#41; NOT NULL AUTO_INCREMENT, `name` VARCHAR&#40;20&#41; NOT NULL, `email` [...]]]></description>
			<content:encoded><![CDATA[<p>Just learned today that for char or varchar columns, MySQL ignores trailing white spaces for comparison in a select statement&#8217;s where clause.</p>
<p>This came as a surprise because I was thinking that the string &#8216;naresh@industriallogic.com&#8217; is different from  &#8216;naresh@industriallogic.com &#8216;.</p>

<div class="wp_syntax"><div class="code"><pre class="sql" style="font-family:monospace;">mysql<span style="color: #66cc66;">&gt;</span> <span style="color: #993333; font-weight: bold;">CREATE</span> <span style="color: #993333; font-weight: bold;">TABLE</span> <span style="color: #ff0000;">`mysql_trailing_test`</span> <span style="color: #66cc66;">&#40;</span>
<span style="color: #ff0000;">`id`</span> <span style="color: #993333; font-weight: bold;">BIGINT</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">20</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span> <span style="color: #993333; font-weight: bold;">AUTO_INCREMENT</span><span style="color: #66cc66;">,</span>
<span style="color: #ff0000;">`name`</span> <span style="color: #993333; font-weight: bold;">VARCHAR</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">20</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
<span style="color: #ff0000;">`email`</span> <span style="color: #993333; font-weight: bold;">VARCHAR</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">50</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
<span style="color: #993333; font-weight: bold;">PRIMARY</span> <span style="color: #993333; font-weight: bold;">KEY</span> <span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">`id`</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span>
<span style="color: #993333; font-weight: bold;">UNIQUE</span> <span style="color: #993333; font-weight: bold;">KEY</span> <span style="color: #ff0000;">`email`</span> <span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">`email`</span><span style="color: #66cc66;">&#41;</span> 
<span style="color: #66cc66;">&#41;</span> ENGINE<span style="color: #66cc66;">=</span>MyISAM <span style="color: #993333; font-weight: bold;">DEFAULT</span> CHARSET<span style="color: #66cc66;">=</span>utf8;</pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="sql" style="font-family:monospace;">mysql<span style="color: #66cc66;">&gt;</span> <span style="color: #993333; font-weight: bold;">INSERT</span> <span style="color: #993333; font-weight: bold;">INTO</span> <span style="color: #ff0000;">`mysql_trailing_test`</span> <span style="color: #993333; font-weight: bold;">VALUES</span> <span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">'Naresh'</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">'naresh@industriallogic.com'</span><span style="color: #66cc66;">&#41;</span>;</pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="sql" style="font-family:monospace;">mysql<span style="color: #66cc66;">&gt;</span> <span style="color: #993333; font-weight: bold;">SELECT</span> <span style="color: #66cc66;">*</span> <span style="color: #993333; font-weight: bold;">FROM</span> <span style="color: #ff0000;">`mysql_trailing_test`</span> <span style="color: #993333; font-weight: bold;">WHERE</span> name<span style="color: #66cc66;">=</span><span style="color: #ff0000;">'Naresh'</span>;</pre></div></div>

<table>
<tr>
<th>id</th>
<th>name</th>
<th>email</th>
</tr>
<tr>
<td>1</td>
<td>Naresh</td>
<td>naresh@industriallogic.com</td>
</tr>
</table>
<p>1 row in set (0.01 sec)</p>
<p>Perfect, as expected. But watch now:</p>

<div class="wp_syntax"><div class="code"><pre class="sql" style="font-family:monospace;">mysql<span style="color: #66cc66;">&gt;</span> <span style="color: #993333; font-weight: bold;">SELECT</span> <span style="color: #66cc66;">*</span> <span style="color: #993333; font-weight: bold;">FROM</span> <span style="color: #ff0000;">`mysql_trailing_test`</span> <span style="color: #993333; font-weight: bold;">WHERE</span> name<span style="color: #66cc66;">=</span><span style="color: #ff0000;">'Naresh '</span>;</pre></div></div>

<table>
<tr>
<th>id</th>
<th>name</th>
<th>email</th>
</tr>
<tr>
<td>1</td>
<td>Naresh</td>
<td>naresh@industriallogic.com</td>
</tr>
</table>
<p>1 row in set (0.01 sec)</p>
<p>AND</p>

<div class="wp_syntax"><div class="code"><pre class="sql" style="font-family:monospace;">mysql<span style="color: #66cc66;">&gt;</span> <span style="color: #993333; font-weight: bold;">INSERT</span> <span style="color: #993333; font-weight: bold;">INTO</span> <span style="color: #ff0000;">`mysql_trailing_test`</span> <span style="color: #993333; font-weight: bold;">VALUES</span> <span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">2</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">'Naresh '</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">'naresh@agilefaqs.com'</span><span style="color: #66cc66;">&#41;</span>;</pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="sql" style="font-family:monospace;">mysql<span style="color: #66cc66;">&gt;</span> <span style="color: #993333; font-weight: bold;">SELECT</span> <span style="color: #66cc66;">*</span> <span style="color: #993333; font-weight: bold;">FROM</span> <span style="color: #ff0000;">`mysql_trailing_test`</span> <span style="color: #993333; font-weight: bold;">WHERE</span> name<span style="color: #66cc66;">=</span><span style="color: #ff0000;">'Naresh'</span>;</pre></div></div>

<table>
<tr>
<th>id</th>
<th>name</th>
<th>email</th>
</tr>
<tr>
<td>1</td>
<td>Naresh</td>
<td>naresh@industriallogic.com</td>
</tr>
<tr>
<td>2</td>
<td>Naresh</td>
<td>naresh@agilefaqs.com</td>
</tr>
</table>
<p>2 row in set (0.01 sec)</p>
<p>Also because of this, if you had a unique constraint on the column and tried to insert another value with trailing space, MySQL would return ERROR 1062 (23000): Duplicate entry.</p>

<div class="wp_syntax"><div class="code"><pre class="sql" style="font-family:monospace;">mysql<span style="color: #66cc66;">&gt;</span> <span style="color: #993333; font-weight: bold;">INSERT</span> <span style="color: #993333; font-weight: bold;">INTO</span> <span style="color: #ff0000;">`mysql_trailing_test`</span> <span style="color: #993333; font-weight: bold;">VALUES</span> <span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">3</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">'Naresh  '</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">'naresh@industriallogic.com '</span><span style="color: #66cc66;">&#41;</span>;</pre></div></div>

<p>ERROR 1062 (23000): Duplicate entry &#8216;naresh@industriallogic.com &#8216; for key &#8216;email&#8217;</p>
<p>More details on <a href="http://dev.mysql.com/doc/refman/5.0/en/char.html" target="_blank">MySQL Documentation: The CHAR and VARCHAR Types</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blogs.agilefaqs.com/2011/06/22/trailing-white-spaces-are-ignored-by-mysql-for-comparison-in-a-select-statement/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Change WordPress Table Prefix using SQL Scripts</title>
		<link>http://blogs.agilefaqs.com/2010/09/07/change-wordpress-table-prefix-using-sql-scripts/</link>
		<comments>http://blogs.agilefaqs.com/2010/09/07/change-wordpress-table-prefix-using-sql-scripts/#comments</comments>
		<pubDate>Tue, 07 Sep 2010 16:47:30 +0000</pubDate>
		<dc:creator>Naresh Jain</dc:creator>
				<category><![CDATA[Database]]></category>
		<category><![CDATA[Deployment]]></category>
		<category><![CDATA[Hosting]]></category>
		<category><![CDATA[Open Source]]></category>
		<category><![CDATA[Tips]]></category>
		<category><![CDATA[database permissions]]></category>
		<category><![CDATA[Word Press]]></category>
		<category><![CDATA[WP Security Scan]]></category>

		<guid isPermaLink="false">http://blogs.agilefaqs.com/?p=1488</guid>
		<description><![CDATA[WP Security Scan Plugin suggests that wordpress users should rename the default wordpress table prefix of wp_ to something else. When I try to do so, I get the following error: Your User which is used to access your WordPress Tables/Database, hasn&#8217;t enough rights( is missing ALTER-right) to alter your Tablestructure. Please visit the plugin [...]]]></description>
			<content:encoded><![CDATA[<p>WP Security Scan Plugin suggests that wordpress users should rename the default wordpress table prefix of wp_ to something else. When I try to do so, I get the following error:</p>
<blockquote><p>Your User which is used to access your WordPress Tables/Database, hasn&#8217;t enough rights( is missing ALTER-right) to alter your Tablestructure. Please visit the plugin documentation for more information. If you believe you have alter rights, please contact the plugin author for assistance.</p></blockquote>
<p>Even though the database user has all the required permissions, I was not successful.</p>
<p>Then I stumbled across <a href="http://tdot-blog.com/wordpress/6-simple-steps-to-change-your-table-prefix-in-wordpress" target="_blank">this blog</a> which shows how to manually update the table prefix.</p>
<p>Inspired by this blog I came up with the following steps to change wordpress table prefix using SQL Scripts.</p>
<p>1- Take a backup</p>
<p>You are about to change your WordPress table structure, it&#8217;s recommend you take a backup first.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">mysqldump -uuser_name <span style="color: #660033;">-ppassword</span> <span style="color: #660033;">-h</span> host db_name <span style="color: #000000; font-weight: bold;">&gt;</span> dbname_backup_date.sql</pre></div></div>

<p>2- Edit your wp-config.php file and change</p>
<blockquote><p>$table_prefix = ‘wp_’;</p></blockquote>
<p>to something like</p>
<blockquote><p>$table_prefix = ‘your_prefix_’;</p></blockquote>
<p>3- Change all your WordPress table names</p>

<div class="wp_syntax"><div class="code"><pre class="sql" style="font-family:monospace;">$mysql <span style="color: #66cc66;">-</span>uuser_name <span style="color: #66cc66;">-</span>ppassword <span style="color: #66cc66;">-</span>h host db_name
&nbsp;
<span style="color: #993333; font-weight: bold;">RENAME</span> <span style="color: #993333; font-weight: bold;">TABLE</span> wp_blc_filters <span style="color: #993333; font-weight: bold;">TO</span> your_prefix_blc_filters;
<span style="color: #993333; font-weight: bold;">RENAME</span> <span style="color: #993333; font-weight: bold;">TABLE</span> wp_blc_instances <span style="color: #993333; font-weight: bold;">TO</span> your_prefix_blc_instances;
<span style="color: #993333; font-weight: bold;">RENAME</span> <span style="color: #993333; font-weight: bold;">TABLE</span> wp_blc_links <span style="color: #993333; font-weight: bold;">TO</span> your_prefix_blc_links;
<span style="color: #993333; font-weight: bold;">RENAME</span> <span style="color: #993333; font-weight: bold;">TABLE</span> wp_blc_synch <span style="color: #993333; font-weight: bold;">TO</span> your_prefix_blc_synch;
<span style="color: #993333; font-weight: bold;">RENAME</span> <span style="color: #993333; font-weight: bold;">TABLE</span> wp_captcha_keys <span style="color: #993333; font-weight: bold;">TO</span> your_prefix_captcha_keys ;
<span style="color: #993333; font-weight: bold;">RENAME</span> <span style="color: #993333; font-weight: bold;">TABLE</span> wp_commentmeta <span style="color: #993333; font-weight: bold;">TO</span> your_prefix_commentmeta;
<span style="color: #993333; font-weight: bold;">RENAME</span> <span style="color: #993333; font-weight: bold;">TABLE</span> wp_comments <span style="color: #993333; font-weight: bold;">TO</span> your_prefix_comments ;
<span style="color: #993333; font-weight: bold;">RENAME</span> <span style="color: #993333; font-weight: bold;">TABLE</span> wp_links <span style="color: #993333; font-weight: bold;">TO</span> your_prefix_links;
<span style="color: #993333; font-weight: bold;">RENAME</span> <span style="color: #993333; font-weight: bold;">TABLE</span> wp_options <span style="color: #993333; font-weight: bold;">TO</span> your_prefix_options;
<span style="color: #993333; font-weight: bold;">RENAME</span> <span style="color: #993333; font-weight: bold;">TABLE</span> wp_postmeta <span style="color: #993333; font-weight: bold;">TO</span> your_prefix_postmeta ;
<span style="color: #993333; font-weight: bold;">RENAME</span> <span style="color: #993333; font-weight: bold;">TABLE</span> wp_posts <span style="color: #993333; font-weight: bold;">TO</span> your_prefix_posts;
<span style="color: #993333; font-weight: bold;">RENAME</span> <span style="color: #993333; font-weight: bold;">TABLE</span> wp_shorturls <span style="color: #993333; font-weight: bold;">TO</span> your_prefix_shorturls;
<span style="color: #993333; font-weight: bold;">RENAME</span> <span style="color: #993333; font-weight: bold;">TABLE</span> wp_sk2_logs <span style="color: #993333; font-weight: bold;">TO</span> your_prefix_sk2_logs ;
<span style="color: #993333; font-weight: bold;">RENAME</span> <span style="color: #993333; font-weight: bold;">TABLE</span> wp_sk2_spams <span style="color: #993333; font-weight: bold;">TO</span> your_prefix_sk2_spams;
<span style="color: #993333; font-weight: bold;">RENAME</span> <span style="color: #993333; font-weight: bold;">TABLE</span> wp_term_relationships <span style="color: #993333; font-weight: bold;">TO</span> your_prefix_term_relationships ;
<span style="color: #993333; font-weight: bold;">RENAME</span> <span style="color: #993333; font-weight: bold;">TABLE</span> wp_term_taxonomy <span style="color: #993333; font-weight: bold;">TO</span> your_prefix_term_taxonomy;
<span style="color: #993333; font-weight: bold;">RENAME</span> <span style="color: #993333; font-weight: bold;">TABLE</span> wp_terms <span style="color: #993333; font-weight: bold;">TO</span> your_prefix_terms;
<span style="color: #993333; font-weight: bold;">RENAME</span> <span style="color: #993333; font-weight: bold;">TABLE</span> wp_ts_favorites <span style="color: #993333; font-weight: bold;">TO</span> your_prefix_ts_favorites ;
<span style="color: #993333; font-weight: bold;">RENAME</span> <span style="color: #993333; font-weight: bold;">TABLE</span> wp_ts_mine <span style="color: #993333; font-weight: bold;">TO</span> your_prefix_ts_mine;
<span style="color: #993333; font-weight: bold;">RENAME</span> <span style="color: #993333; font-weight: bold;">TABLE</span> wp_tweetbacks <span style="color: #993333; font-weight: bold;">TO</span> your_prefix_tweetbacks ;
<span style="color: #993333; font-weight: bold;">RENAME</span> <span style="color: #993333; font-weight: bold;">TABLE</span> wp_usermeta <span style="color: #993333; font-weight: bold;">TO</span> your_prefix_usermeta ;
<span style="color: #993333; font-weight: bold;">RENAME</span> <span style="color: #993333; font-weight: bold;">TABLE</span> wp_users <span style="color: #993333; font-weight: bold;">TO</span> your_prefix_users;
<span style="color: #993333; font-weight: bold;">RENAME</span> <span style="color: #993333; font-weight: bold;">TABLE</span> wp_yarpp_keyword_cache <span style="color: #993333; font-weight: bold;">TO</span> your_prefix_yarpp_keyword_cache;
<span style="color: #993333; font-weight: bold;">RENAME</span> <span style="color: #993333; font-weight: bold;">TABLE</span> wp_yarpp_related_cache <span style="color: #993333; font-weight: bold;">TO</span> your_prefix_yarpp_related_cache;</pre></div></div>

<p>4- Edit wp_options table</p>

<div class="wp_syntax"><div class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">UPDATE</span> your_prefix_options <span style="color: #993333; font-weight: bold;">SET</span> option_name<span style="color: #66cc66;">=</span><span style="color: #ff0000;">'your_prefix_user_roles'</span> <span style="color: #993333; font-weight: bold;">WHERE</span> option_name<span style="color: #66cc66;">=</span><span style="color: #ff0000;">'wp_user_roles'</span>;</pre></div></div>

<p>5- Edit wp_usermeta</p>

<div class="wp_syntax"><div class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">UPDATE</span> your_prefix_usermeta <span style="color: #993333; font-weight: bold;">SET</span> meta_key<span style="color: #66cc66;">=</span><span style="color: #ff0000;">'your_prefix_autosave_draft_ids'</span> <span style="color: #993333; font-weight: bold;">WHERE</span> meta_key<span style="color: #66cc66;">=</span><span style="color: #ff0000;">'wp_autosave_draft_ids'</span>;                 
<span style="color: #993333; font-weight: bold;">UPDATE</span> your_prefix_usermeta <span style="color: #993333; font-weight: bold;">SET</span> meta_key<span style="color: #66cc66;">=</span><span style="color: #ff0000;">'your_prefix_capabilities'</span> <span style="color: #993333; font-weight: bold;">WHERE</span> meta_key<span style="color: #66cc66;">=</span><span style="color: #ff0000;">'wp_capabilities'</span>;                       
<span style="color: #993333; font-weight: bold;">UPDATE</span> your_prefix_usermeta <span style="color: #993333; font-weight: bold;">SET</span> meta_key<span style="color: #66cc66;">=</span><span style="color: #ff0000;">'your_prefix_dashboard_quick_press_last_post_id'</span> <span style="color: #993333; font-weight: bold;">WHERE</span> meta_key<span style="color: #66cc66;">=</span><span style="color: #ff0000;">'wp_dashboard_quick_press_last_post_id'</span>; 
<span style="color: #993333; font-weight: bold;">UPDATE</span> your_prefix_usermeta <span style="color: #993333; font-weight: bold;">SET</span> meta_key<span style="color: #66cc66;">=</span><span style="color: #ff0000;">'your_prefix_user-settings'</span> <span style="color: #993333; font-weight: bold;">WHERE</span> meta_key<span style="color: #66cc66;">=</span><span style="color: #ff0000;">'wp_user-settings'</span>;                      
<span style="color: #993333; font-weight: bold;">UPDATE</span> your_prefix_usermeta <span style="color: #993333; font-weight: bold;">SET</span> meta_key<span style="color: #66cc66;">=</span><span style="color: #ff0000;">'your_prefix_user-settings-time'</span> <span style="color: #993333; font-weight: bold;">WHERE</span> meta_key<span style="color: #66cc66;">=</span><span style="color: #ff0000;">'wp_user-settings-time'</span>;                 
<span style="color: #993333; font-weight: bold;">UPDATE</span> your_prefix_usermeta <span style="color: #993333; font-weight: bold;">SET</span> meta_key<span style="color: #66cc66;">=</span><span style="color: #ff0000;">'your_prefix_usersettings'</span> <span style="color: #993333; font-weight: bold;">WHERE</span> meta_key<span style="color: #66cc66;">=</span><span style="color: #ff0000;">'wp_usersettings'</span>;                       
<span style="color: #993333; font-weight: bold;">UPDATE</span> your_prefix_usermeta <span style="color: #993333; font-weight: bold;">SET</span> meta_key<span style="color: #66cc66;">=</span><span style="color: #ff0000;">'your_prefix_usersettingstime'</span> <span style="color: #993333; font-weight: bold;">WHERE</span> meta_key<span style="color: #66cc66;">=</span><span style="color: #ff0000;">'wp_usersettingstime'</span>;</pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://blogs.agilefaqs.com/2010/09/07/change-wordpress-table-prefix-using-sql-scripts/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>MySQL Load Data Infile: ERROR 1045 (28000): Access denied for user&#8230;</title>
		<link>http://blogs.agilefaqs.com/2010/04/05/mysql-load-data-infile-error-1045-28000-access-denied-for-user/</link>
		<comments>http://blogs.agilefaqs.com/2010/04/05/mysql-load-data-infile-error-1045-28000-access-denied-for-user/#comments</comments>
		<pubDate>Mon, 05 Apr 2010 10:29:56 +0000</pubDate>
		<dc:creator>Naresh Jain</dc:creator>
				<category><![CDATA[Database]]></category>
		<category><![CDATA[Deployment]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[access denied]]></category>
		<category><![CDATA[chown]]></category>
		<category><![CDATA[error 1045]]></category>
		<category><![CDATA[load data infile]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[mysqlimport]]></category>

		<guid isPermaLink="false">http://blogs.agilefaqs.com/?p=1233</guid>
		<description><![CDATA[Recently I was trying to load a CSV file into a MySQL database on a Linux box using the following command: LOAD DATA INFILE '/path/to/my_data.csv' INTO TABLE `my_data` FIELDS TERMINATED BY ',' ENCLOSED BY '"' LINES TERMINATED BY '\r\n'; I kept getting the following error: ERROR 1045 (28000): Access denied for user &#8230; After Googling [...]]]></description>
			<content:encoded><![CDATA[<p>Recently I was trying to load a CSV file into a MySQL database on a Linux box using the following command:</p>
<pre class="bash">
LOAD DATA INFILE '/path/to/my_data.csv' INTO TABLE `my_data`
        FIELDS TERMINATED BY ',' ENCLOSED BY '"'
        LINES TERMINATED BY '\r\n';
</pre>
<p>I kept getting the following error:</p>
<p>ERROR 1045 (28000): Access denied for user &#8230;</p>
<p>After Googling around I got some suggestions:</p>
<ul>
<li>chown mysql.mysql my_data.csv; chmod 666 my_data.csv</li>
<li>move the data file to /tmp folder, where all processes have read access</li>
<li>Grant a FILE permissions to the user. Basically GRANT *.* usage.</li>
<li>Load data <strong>LOCAL</strong> infile&#8230;</li>
</ul>
<p>Nothing seemed to help.</p>
<p>Luckily I found the following command which did the job:</p>
<pre class="bash">
mysqlimport -v --local --fields-enclosed-by='"'
        --fields-escaped-by='\'
        --fields-terminated-by=','
        --lines-terminated-by='\r\n'
        -u[db_user] -p[db_password] -h [hostname] [db_name]
        '/path/to/my_data.csv'
</pre>
]]></content:encoded>
			<wfw:commentRss>http://blogs.agilefaqs.com/2010/04/05/mysql-load-data-infile-error-1045-28000-access-denied-for-user/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Could not inspect JDBC autocommit mode</title>
		<link>http://blogs.agilefaqs.com/2010/01/09/could-not-inspect-jdbc-autocommit-mode/</link>
		<comments>http://blogs.agilefaqs.com/2010/01/09/could-not-inspect-jdbc-autocommit-mode/#comments</comments>
		<pubDate>Fri, 08 Jan 2010 20:48:04 +0000</pubDate>
		<dc:creator>Naresh Jain</dc:creator>
				<category><![CDATA[Database]]></category>
		<category><![CDATA[Tips]]></category>
		<category><![CDATA[Connection]]></category>
		<category><![CDATA[DBCP]]></category>
		<category><![CDATA[Hibernate]]></category>
		<category><![CDATA[JDBC]]></category>
		<category><![CDATA[tomcat]]></category>
		<category><![CDATA[validationQuery]]></category>

		<guid isPermaLink="false">http://blogs.agilefaqs.com/?p=1147</guid>
		<description><![CDATA[After switching to the DBCP (Database Connection Pool) drivers that comes bundled with Tomcat 5+, we started seeing a weird exception on our web app. If we leave our server idle for a long time (5-6 hrs) or if we put our laptop to sleep and 5-6+ hrs later when we bring up the laptop [...]]]></description>
			<content:encoded><![CDATA[<p>After switching to the DBCP (Database Connection Pool) drivers that comes bundled with Tomcat 5+, we started seeing a weird exception on our web app. If we leave our server idle for a long time (5-6 hrs) or if we put our laptop to sleep and 5-6+ hrs later when we bring up the laptop and try to access any page on our web app, we get the following error on the web page:</p>
<p>(The error was &#8220;could not inspect JDBC autocommit mode&#8221;)</p>
<p>When we see our logs, we find the following exception:</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #cc66cc;">18</span><span style="color: #339933;">:</span><span style="color: #cc66cc;">26</span><span style="color: #339933;">:</span><span style="color: #cc66cc;">34</span>,<span style="color: #cc66cc;">845</span> ERROR JDBCExceptionReporter<span style="color: #339933;">:</span><span style="color: #cc66cc;">72</span> <span style="color: #339933;">-</span> <span style="color: #003399;">Connection</span> com.<span style="color: #006633;">mysql</span>.<span style="color: #006633;">jdbc</span>.<span style="color: #006633;">JDBC4Connection</span>@36fbe6ab is closed.
<span style="color: #006633;">SEVERE</span><span style="color: #339933;">:</span> could not inspect JDBC autocommit mode
org.<span style="color: #006633;">hibernate</span>.<span style="color: #006633;">exception</span>.<span style="color: #006633;">GenericJDBCException</span><span style="color: #339933;">:</span> could not inspect JDBC autocommit mode
	at org.<span style="color: #006633;">hibernate</span>.<span style="color: #006633;">exception</span>.<span style="color: #006633;">SQLStateConverter</span>.<span style="color: #006633;">handledNonSpecificException</span><span style="color: #009900;">&#40;</span>SQLStateConverter.<span style="color: #006633;">java</span><span style="color: #339933;">:</span><span style="color: #cc66cc;">103</span><span style="color: #009900;">&#41;</span>
	at org.<span style="color: #006633;">hibernate</span>.<span style="color: #006633;">exception</span>.<span style="color: #006633;">SQLStateConverter</span>.<span style="color: #006633;">convert</span><span style="color: #009900;">&#40;</span>SQLStateConverter.<span style="color: #006633;">java</span><span style="color: #339933;">:</span><span style="color: #cc66cc;">91</span><span style="color: #009900;">&#41;</span>
	at org.<span style="color: #006633;">hibernate</span>.<span style="color: #006633;">exception</span>.<span style="color: #006633;">JDBCExceptionHelper</span>.<span style="color: #006633;">convert</span><span style="color: #009900;">&#40;</span>JDBCExceptionHelper.<span style="color: #006633;">java</span><span style="color: #339933;">:</span><span style="color: #cc66cc;">43</span><span style="color: #009900;">&#41;</span>
	at org.<span style="color: #006633;">hibernate</span>.<span style="color: #006633;">exception</span>.<span style="color: #006633;">JDBCExceptionHelper</span>.<span style="color: #006633;">convert</span><span style="color: #009900;">&#40;</span>JDBCExceptionHelper.<span style="color: #006633;">java</span><span style="color: #339933;">:</span><span style="color: #cc66cc;">29</span><span style="color: #009900;">&#41;</span>
	at org.<span style="color: #006633;">hibernate</span>.<span style="color: #006633;">jdbc</span>.<span style="color: #006633;">JDBCContext</span>.<span style="color: #006633;">afterNontransactionalQuery</span><span style="color: #009900;">&#40;</span>JDBCContext.<span style="color: #006633;">java</span><span style="color: #339933;">:</span><span style="color: #cc66cc;">248</span><span style="color: #009900;">&#41;</span>
	at org.<span style="color: #006633;">hibernate</span>.<span style="color: #006633;">impl</span>.<span style="color: #006633;">SessionImpl</span>.<span style="color: #006633;">afterOperation</span><span style="color: #009900;">&#40;</span>SessionImpl.<span style="color: #006633;">java</span><span style="color: #339933;">:</span><span style="color: #cc66cc;">417</span><span style="color: #009900;">&#41;</span>
	at org.<span style="color: #006633;">hibernate</span>.<span style="color: #006633;">impl</span>.<span style="color: #006633;">SessionImpl</span>.<span style="color: #006633;">list</span><span style="color: #009900;">&#40;</span>SessionImpl.<span style="color: #006633;">java</span><span style="color: #339933;">:</span><span style="color: #cc66cc;">1577</span><span style="color: #009900;">&#41;</span>
	at org.<span style="color: #006633;">hibernate</span>.<span style="color: #006633;">impl</span>.<span style="color: #006633;">CriteriaImpl</span>.<span style="color: #006633;">list</span><span style="color: #009900;">&#40;</span>CriteriaImpl.<span style="color: #006633;">java</span><span style="color: #339933;">:</span><span style="color: #cc66cc;">283</span><span style="color: #009900;">&#41;</span>
	...
	<span style="color: #006633;">at</span> javax.<span style="color: #006633;">servlet</span>.<span style="color: #006633;">http</span>.<span style="color: #006633;">HttpServlet</span>.<span style="color: #006633;">service</span><span style="color: #009900;">&#40;</span>HttpServlet.<span style="color: #006633;">java</span><span style="color: #339933;">:</span><span style="color: #cc66cc;">617</span><span style="color: #009900;">&#41;</span>
	at javax.<span style="color: #006633;">servlet</span>.<span style="color: #006633;">http</span>.<span style="color: #006633;">HttpServlet</span>.<span style="color: #006633;">service</span><span style="color: #009900;">&#40;</span>HttpServlet.<span style="color: #006633;">java</span><span style="color: #339933;">:</span><span style="color: #cc66cc;">717</span><span style="color: #009900;">&#41;</span>
	at org.<span style="color: #006633;">apache</span>.<span style="color: #006633;">catalina</span>.<span style="color: #006633;">core</span>.<span style="color: #006633;">ApplicationFilterChain</span>.<span style="color: #006633;">internalDoFilter</span><span style="color: #009900;">&#40;</span>ApplicationFilterChain.<span style="color: #006633;">java</span><span style="color: #339933;">:</span><span style="color: #cc66cc;">290</span><span style="color: #009900;">&#41;</span>
	at org.<span style="color: #006633;">apache</span>.<span style="color: #006633;">catalina</span>.<span style="color: #006633;">core</span>.<span style="color: #006633;">ApplicationFilterChain</span>.<span style="color: #006633;">doFilter</span><span style="color: #009900;">&#40;</span>ApplicationFilterChain.<span style="color: #006633;">java</span><span style="color: #339933;">:</span><span style="color: #cc66cc;">206</span><span style="color: #009900;">&#41;</span>
	at org.<span style="color: #006633;">apache</span>.<span style="color: #006633;">catalina</span>.<span style="color: #006633;">core</span>.<span style="color: #006633;">StandardWrapperValve</span>.<span style="color: #006633;">invoke</span><span style="color: #009900;">&#40;</span>StandardWrapperValve.<span style="color: #006633;">java</span><span style="color: #339933;">:</span><span style="color: #cc66cc;">233</span><span style="color: #009900;">&#41;</span>
	at org.<span style="color: #006633;">apache</span>.<span style="color: #006633;">catalina</span>.<span style="color: #006633;">core</span>.<span style="color: #006633;">StandardContextValve</span>.<span style="color: #006633;">invoke</span><span style="color: #009900;">&#40;</span>StandardContextValve.<span style="color: #006633;">java</span><span style="color: #339933;">:</span><span style="color: #cc66cc;">191</span><span style="color: #009900;">&#41;</span>
	at org.<span style="color: #006633;">apache</span>.<span style="color: #006633;">catalina</span>.<span style="color: #006633;">core</span>.<span style="color: #006633;">StandardHostValve</span>.<span style="color: #006633;">invoke</span><span style="color: #009900;">&#40;</span>StandardHostValve.<span style="color: #006633;">java</span><span style="color: #339933;">:</span><span style="color: #cc66cc;">128</span><span style="color: #009900;">&#41;</span>
	at org.<span style="color: #006633;">apache</span>.<span style="color: #006633;">catalina</span>.<span style="color: #006633;">valves</span>.<span style="color: #006633;">ErrorReportValve</span>.<span style="color: #006633;">invoke</span><span style="color: #009900;">&#40;</span>ErrorReportValve.<span style="color: #006633;">java</span><span style="color: #339933;">:</span><span style="color: #cc66cc;">102</span><span style="color: #009900;">&#41;</span>
	at org.<span style="color: #006633;">apache</span>.<span style="color: #006633;">catalina</span>.<span style="color: #006633;">core</span>.<span style="color: #006633;">StandardEngineValve</span>.<span style="color: #006633;">invoke</span><span style="color: #009900;">&#40;</span>StandardEngineValve.<span style="color: #006633;">java</span><span style="color: #339933;">:</span><span style="color: #cc66cc;">109</span><span style="color: #009900;">&#41;</span>
	at org.<span style="color: #006633;">apache</span>.<span style="color: #006633;">catalina</span>.<span style="color: #006633;">ha</span>.<span style="color: #006633;">tcp</span>.<span style="color: #006633;">ReplicationValve</span>.<span style="color: #006633;">invoke</span><span style="color: #009900;">&#40;</span>ReplicationValve.<span style="color: #006633;">java</span><span style="color: #339933;">:</span><span style="color: #cc66cc;">347</span><span style="color: #009900;">&#41;</span>
	at org.<span style="color: #006633;">apache</span>.<span style="color: #006633;">catalina</span>.<span style="color: #006633;">connector</span>.<span style="color: #006633;">CoyoteAdapter</span>.<span style="color: #006633;">service</span><span style="color: #009900;">&#40;</span>CoyoteAdapter.<span style="color: #006633;">java</span><span style="color: #339933;">:</span><span style="color: #cc66cc;">286</span><span style="color: #009900;">&#41;</span>
	at org.<span style="color: #006633;">apache</span>.<span style="color: #006633;">coyote</span>.<span style="color: #006633;">http11</span>.<span style="color: #006633;">Http11Processor</span>.<span style="color: #006633;">process</span><span style="color: #009900;">&#40;</span>Http11Processor.<span style="color: #006633;">java</span><span style="color: #339933;">:</span><span style="color: #cc66cc;">845</span><span style="color: #009900;">&#41;</span>
	at org.<span style="color: #006633;">apache</span>.<span style="color: #006633;">coyote</span>.<span style="color: #006633;">http11</span>.<span style="color: #006633;">Http11Protocol</span>$Http11ConnectionHandler.<span style="color: #006633;">process</span><span style="color: #009900;">&#40;</span>Http11Protocol.<span style="color: #006633;">java</span><span style="color: #339933;">:</span><span style="color: #cc66cc;">583</span><span style="color: #009900;">&#41;</span>
	at org.<span style="color: #006633;">apache</span>.<span style="color: #006633;">tomcat</span>.<span style="color: #006633;">util</span>.<span style="color: #006633;">net</span>.<span style="color: #006633;">JIoEndpoint</span>$Worker.<span style="color: #006633;">run</span><span style="color: #009900;">&#40;</span>JIoEndpoint.<span style="color: #006633;">java</span><span style="color: #339933;">:</span><span style="color: #cc66cc;">447</span><span style="color: #009900;">&#41;</span>
	at java.<span style="color: #006633;">lang</span>.<span style="color: #003399;">Thread</span>.<span style="color: #006633;">run</span><span style="color: #009900;">&#40;</span><span style="color: #003399;">Thread</span>.<span style="color: #006633;">java</span><span style="color: #339933;">:</span><span style="color: #cc66cc;">637</span><span style="color: #009900;">&#41;</span>
Caused by<span style="color: #339933;">:</span> java.<span style="color: #006633;">sql</span>.<span style="color: #003399;">SQLException</span><span style="color: #339933;">:</span> <span style="color: #003399;">Connection</span> com.<span style="color: #006633;">mysql</span>.<span style="color: #006633;">jdbc</span>.<span style="color: #006633;">JDBC4Connection</span>@36fbe6ab is closed.
	<span style="color: #006633;">at</span> org.<span style="color: #006633;">apache</span>.<span style="color: #006633;">tomcat</span>.<span style="color: #006633;">dbcp</span>.<span style="color: #006633;">dbcp</span>.<span style="color: #006633;">DelegatingConnection</span>.<span style="color: #006633;">checkOpen</span><span style="color: #009900;">&#40;</span>DelegatingConnection.<span style="color: #006633;">java</span><span style="color: #339933;">:</span><span style="color: #cc66cc;">354</span><span style="color: #009900;">&#41;</span>
	at org.<span style="color: #006633;">apache</span>.<span style="color: #006633;">tomcat</span>.<span style="color: #006633;">dbcp</span>.<span style="color: #006633;">dbcp</span>.<span style="color: #006633;">DelegatingConnection</span>.<span style="color: #006633;">getAutoCommit</span><span style="color: #009900;">&#40;</span>DelegatingConnection.<span style="color: #006633;">java</span><span style="color: #339933;">:</span><span style="color: #cc66cc;">304</span><span style="color: #009900;">&#41;</span>
	at org.<span style="color: #006633;">apache</span>.<span style="color: #006633;">tomcat</span>.<span style="color: #006633;">dbcp</span>.<span style="color: #006633;">dbcp</span>.<span style="color: #006633;">PoolingDataSource</span>$PoolGuardConnectionWrapper.<span style="color: #006633;">getAutoCommit</span><span style="color: #009900;">&#40;</span>PoolingDataSource.<span style="color: #006633;">java</span><span style="color: #339933;">:</span><span style="color: #cc66cc;">224</span><span style="color: #009900;">&#41;</span>
	at org.<span style="color: #006633;">hibernate</span>.<span style="color: #006633;">jdbc</span>.<span style="color: #006633;">ConnectionManager</span>.<span style="color: #006633;">isAutoCommit</span><span style="color: #009900;">&#40;</span>ConnectionManager.<span style="color: #006633;">java</span><span style="color: #339933;">:</span><span style="color: #cc66cc;">185</span><span style="color: #009900;">&#41;</span>
	at org.<span style="color: #006633;">hibernate</span>.<span style="color: #006633;">jdbc</span>.<span style="color: #006633;">JDBCContext</span>.<span style="color: #006633;">afterNontransactionalQuery</span><span style="color: #009900;">&#40;</span>JDBCContext.<span style="color: #006633;">java</span><span style="color: #339933;">:</span><span style="color: #cc66cc;">239</span><span style="color: #009900;">&#41;</span>
	... <span style="color: #cc66cc;">29</span> more</pre></div></div>

<p>On carefully looking at the exception, we find:</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;">Caused by<span style="color: #339933;">:</span> java.<span style="color: #006633;">sql</span>.<span style="color: #003399;">SQLException</span><span style="color: #339933;">:</span> <span style="color: #003399;">Connection</span> com.<span style="color: #006633;">mysql</span>.<span style="color: #006633;">jdbc</span>.<span style="color: #006633;">JDBC4Connection</span>@36fbe6ab is closed.</pre></div></div>

<p>From the exception its clear that the reason for this exception is that the db connection is closed. Which is in sync with our finding so far, idle server causes this problem.</p>
<p>What happens is, the Database closes the connections since they are inactive. But DBCP &amp; hence hibernate still thinks those connections are active and tries to execute some command on them. This is when an exception is thrown.</p>
<p>We can easily simulate this exception. When everything is running fine, restart your DB and you&#8217;ll see the same exception when you try to access any dynamic page on your site.</p>
<p>On reading <a href="http://commons.apache.org/dbcp/configuration.html" target="_blank">DBCP configuration</a>, I found:</p>
<table>
<tr>
<th class="first">Parameter</th>
<th>Default</th>
<th class="last">Description</th>
</tr>
<tr class="a">
<td>validationQuery</td>
<td></td>
<td>
The SQL query that will be used to validate connections from this pool<br />
before returning them to the caller.  If specified, this query<br />
<strong>MUST</strong> be an SQL SELECT statement that returns at least<br />
one row.
   </td>
</tr>
<tr class="b">
<td>testOnBorrow</td>
<td>true</td>
<td>
      The indication of whether objects will be validated before being<br />
      borrowed from the pool.  If the object fails to validate, it will be<br />
      dropped from the pool, and we will attempt to borrow another.<br />
<strong>NOTE</strong> &#8211; for a <code>true</code> value to have any effect,<br />
      the <code>validationQuery</code> parameter must be set to a non-null<br />
      string.
   </td>
</tr>
</table>
<p>Basically testOnBorrow is true by default, which means DBCP will test if the connection is valid (alive) before returning. But to test it, it needs a query using which it would validate the connection. Since in our case we did not specify any value, when hibernate would ask DBCP for a connection, it would just return a connection without testing if its a valid connection before returning. And then the stale connection throws an exception when we try to perform any operation on it. But if the validation query is specified, then DBCP will drop the connection and give us another valid connection. This avoiding this problem.</p>
<p>So the simple solution to this problem is to add a validationQuery to the connection pooling configuration (in our case it was the context.xml file).</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;">validationQuery<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;select version();&quot;</span></pre></div></div>

<p>Q.E.D</p>
]]></content:encoded>
			<wfw:commentRss>http://blogs.agilefaqs.com/2010/01/09/could-not-inspect-jdbc-autocommit-mode/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Restoring Master database on MS SQLExpress</title>
		<link>http://blogs.agilefaqs.com/2008/11/10/restoring-master-database-on-ms-sqlexpress/</link>
		<comments>http://blogs.agilefaqs.com/2008/11/10/restoring-master-database-on-ms-sqlexpress/#comments</comments>
		<pubDate>Mon, 10 Nov 2008 10:49:37 +0000</pubDate>
		<dc:creator>Naresh Jain</dc:creator>
				<category><![CDATA[Database]]></category>
		<category><![CDATA[Tips]]></category>

		<guid isPermaLink="false">http://blogs.agilefaqs.com/?p=371</guid>
		<description><![CDATA[Today all of a sudden, one of my MsSQLExpress servers refused to start. On looking at the Windows Event Log, I discovered the following errors: FCB::Open failed: Could not open file c:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQ\DATA\mastlog.ldf for file number 2. OS error: 2(The system cannot find the file specified.)/ FCB::Open: Operating system error 2(The system cannot [...]]]></description>
			<content:encoded><![CDATA[<p>Today all of a sudden, one of my <a href="http://www.microsoft.com/Sqlserver/2005/en/us/express.aspx" target="_blank">MsSQLExpress</a> servers refused to start. On looking at the Windows Event Log, I discovered the following errors:</p>
<blockquote><p>FCB::Open failed: Could not open file c:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQ\DATA\mastlog.ldf for file number 2.  OS error: 2(The system cannot find the file specified.)/</p></blockquote>
<blockquote><p>FCB::Open: Operating system error 2(The system cannot find the file specified.) occurred while creating or opening file &#8216;c:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\DATA\mastlog.ldf&#8217;. Diagnose and correct the operating system error, and retry the operation.</p></blockquote>
<p>I wanted to find a way to quickly restore the Master database. Unfortunately I did not have any backup. (This was a playground server, not a production box). Since I had nothing changed on the master db, restoring a fresh copy would not make any difference.</p>
<p>Luckily I found out that there is a directory called &#8220;C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Template Data&#8221; and as the name suggests it contains a template DB. So I simply replaced master.mdf and mastlog.ldf files in &#8220;C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Data&#8221; directory with those found under the Template Data directory.</p>
<p>Hurray! My MsSQLExpress server started fine without any further complains.</p>
]]></content:encoded>
			<wfw:commentRss>http://blogs.agilefaqs.com/2008/11/10/restoring-master-database-on-ms-sqlexpress/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>MySQL Table Crash</title>
		<link>http://blogs.agilefaqs.com/2008/02/02/mysql-table-crash/</link>
		<comments>http://blogs.agilefaqs.com/2008/02/02/mysql-table-crash/#comments</comments>
		<pubDate>Sat, 02 Feb 2008 18:11:05 +0000</pubDate>
		<dc:creator>Naresh Jain</dc:creator>
				<category><![CDATA[Database]]></category>

		<guid isPermaLink="false">http://blogs.agilefaqs.com/2008/02/02/mysql-table-crash/</guid>
		<description><![CDATA[I&#8217;m using TikiWiki with MySQL database for SDTConf and AgileCoachCamp wiki. Recently both these wikis were down with the following error: On googling about it, I found: &#8220;One common cause of this is the disk hitting 100%, so use df and du -sk / to try and figure out where your clogs are.&#8221; In my [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m using TikiWiki with MySQL database for SDTConf and AgileCoachCamp wiki. Recently both these wikis were down with the following error:<br />
<a href='http://blogs.agilefaqs.com/wp-content/uploads/2008/02/mysqltablecrash.png' title='Wiki Error due to MySQL Table Crash'><img src='http://blogs.agilefaqs.com/wp-content/uploads/2008/02/mysqltablecrash.png' alt='Wiki Error due to MySQL Table Crash' /></a></p>
<p>On googling about it, I found: &#8220;One common cause of this is the disk hitting 100%, so use df and du -sk / to try and figure out where your clogs are.&#8221; In my case, I&#8217;m pretty sure that I have enough disk space. I&#8217;m still not sure what caused this. But I found a work around to solve the problem at hand. If any one has ideas about this, I was be eager to hear about it.</p>
<p>Solution: execute the following command:<br />
mysqlcheck &#8211;auto-repair -u{username} -p{password} {database_name} {database_table_name}</p>
]]></content:encoded>
			<wfw:commentRss>http://blogs.agilefaqs.com/2008/02/02/mysql-table-crash/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Concurrency Control</title>
		<link>http://blogs.agilefaqs.com/2005/03/23/concurrency-control/</link>
		<comments>http://blogs.agilefaqs.com/2005/03/23/concurrency-control/#comments</comments>
		<pubDate>Wed, 23 Mar 2005 06:26:09 +0000</pubDate>
		<dc:creator>Naresh Jain</dc:creator>
				<category><![CDATA[Database]]></category>

		<guid isPermaLink="false">http://blogs.agilefaqs.com/?p=118</guid>
		<description><![CDATA[Three types of concurrency control: Pessimistic concurrency control: a record is unavailable to users while somebody else is accessing it. i.e. from the time the record is fetched until it is updated in the database. The way this is implemented is, the moment someone fetches a record, a lock is acquired on that table and [...]]]></description>
			<content:encoded><![CDATA[<p><b>Three types of concurrency control:</b></p>
<p><b>Pessimistic concurrency control</b>:  a record is unavailable to users while somebody else is accessing it. i.e. from the time the record is fetched until it is updated in the database. The way this is implemented is, the moment someone fetches a record, a lock is acquired on that table and no other user is allowed to access the same table until the lock is released.</p>
<p><b>Optimistic concurrency control</b>:  a record is unavailable to other users only while the data is actually being updated. The way this is implemented is, the update examines the record in the database and determines whether any changes have been made. Attempting to update a changed record results in a concurrency violation and hence an exception.</p>
<p><b>Last in Wins</b>: a record is never unavailable to the users. Every time the user updates the record is simply saved without checking for updates on the record. This can potentially overwrite any changes made by other users since you last refreshed the records. This is the easiest to implement and the most dangerous to use.</p>
<p><b>Implementation details:</b></p>
<p><b>Pessimistic concurrency control (PCC):</b><br />
It can be implemented with or without using database locks. It&#8216;s usually implemented on the application side. Database locks are available in very limited <span class="caps">DBMS</span> and hence it&#8216;s a good idea not to use database locks.</p>
<p>Most of the applications today have a multi-layered architecture and have a separate layer for database access. <span class="caps">PCC</span> is mostly implemented in the data access layer or the service layer. We can maintain a static list of tables, which are currently been accessed. Before processing any request for a record, we check in this list. If the table is present in the list, then we throw an exception, else add it to the table and fetch the data. There is an alternative to the static table. One can use lock-bits at the table record level and maintain them in a session pool.</p>
<p>The static list or the lock-bits can be cleared when the user leaves the page under program control. This is done to free the locks as soon as possible, but there is no guarantee that this will occur.<br />
As the user can leave the browser or the site at any moment, we have to clear the list or lock-bits stored are the session pool on Session End. And as a final countermeasure, we might have a demon running on the server cleaning old locks.</p>
<p>We have to keep in mind that an application that holds locks for long periods is not scalable.</p>
<p><b>Last in Wins</b><br />
This concurrency control can be implemented without having to do anything. This is the default behavior. But this might be unacceptable in some circumstances if different users start to access the same records frequently.</p>
<p><b>Optimistic concurrency control (OCC)</b><br />
In <span class="caps">OCC</span>, several users can access a screen for the same record, but only the first one to save it will succeed. The rest would get concurrent change exception.</p>
<p><span class="caps">OCC</span> is implemented based on the record version. The record version could mean all the columns of the record or a unique state code. For the unique code purpose we can use a <span class="caps">GUID</span> string or a date-time value. I&#8216;m not too sure which one to use. But these are some points:</p>
<p>The <span class="caps">GUID</span> is not portable if we want to port the code to other platforms.<br />
The <span class="caps">GUID</span> uses 40 bytes of binary data instead of the 8 bytes used by the date.<br />
The date-time tells us when the record was last updated.</p>
<p>Example:<br />
User A fetches a record from the database along with its version, more on this later.<br />
User B fetches the same record from the database, also with its version and writes the updated record back to the database, updating the version number.<br />
User A &#8220;tries&#8221; to write the record to the database, but as the version on the database is different from the version hold by user A, the write fails, leaving user B&#8216;s changes intact.</p>
<p>It&#8216;s always favorable to use <span class="caps">OCC</span>. But there might be situations where we have a long transaction, which spans over several screens. The user might not want to get concurrent change exception at the end of the updation. In these cases, it&#8216;s better to use <span class="caps">PCC</span> and let the user know upfront about any possible locks.</p>
]]></content:encoded>
			<wfw:commentRss>http://blogs.agilefaqs.com/2005/03/23/concurrency-control/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Stored proc to page sorted data</title>
		<link>http://blogs.agilefaqs.com/2005/01/17/stored-proc-to-page-sorted-data/</link>
		<comments>http://blogs.agilefaqs.com/2005/01/17/stored-proc-to-page-sorted-data/#comments</comments>
		<pubDate>Mon, 17 Jan 2005 13:48:37 +0000</pubDate>
		<dc:creator>Naresh Jain</dc:creator>
				<category><![CDATA[Database]]></category>

		<guid isPermaLink="false">http://blogs.agilefaqs.com/?p=133</guid>
		<description><![CDATA[Requirement: You have a portal which display a huge amount of data stored in the database. The web page essentially looks like an ancient VB app with all the winform kind of a look. The user wants to page the data that is retrieved from the database. Also at&#8230; Read More]]></description>
			<content:encoded><![CDATA[<p>Requirement: You have a portal which display a huge amount of data stored in the database. The web page essentially looks like an ancient VB app with all the winform kind of a look. The user wants to page the data that is retrieved from the database. Also at&#8230;
<div class="readMore"><a href="http://jroller.com/page/njain?entry=stored_proc_to_page_sorted">Read More</a></div>
]]></content:encoded>
			<wfw:commentRss>http://blogs.agilefaqs.com/2005/01/17/stored-proc-to-page-sorted-data/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to delete a Global temp Table?</title>
		<link>http://blogs.agilefaqs.com/2005/01/14/how-to-delete-a-global-temp-table/</link>
		<comments>http://blogs.agilefaqs.com/2005/01/14/how-to-delete-a-global-temp-table/#comments</comments>
		<pubDate>Fri, 14 Jan 2005 05:38:35 +0000</pubDate>
		<dc:creator>Naresh Jain</dc:creator>
				<category><![CDATA[Database]]></category>

		<guid isPermaLink="false">http://blogs.agilefaqs.com/?p=134</guid>
		<description><![CDATA[Recently I had a situation where I had to create a &#8216;Global Temp Table&#8216; inside a &#8216;T-SQL Stored Procedure&#8216;. Though I was deleting the temp table at the end of the stored proc, there were some issues. The temp table was not deleted if&#8230; Read More]]></description>
			<content:encoded><![CDATA[<p>Recently I had a situation where I had to create a &#8216;Global Temp Table&#8216; inside a &#8216;T-SQL Stored Procedure&#8216;. Though I was deleting the temp table at the end of the stored proc, there were some issues. The temp table was not deleted if&#8230;
<div class="readMore"><a href="http://jroller.com/page/njain?entry=how_to_delete_a_global">Read More</a></div>
]]></content:encoded>
			<wfw:commentRss>http://blogs.agilefaqs.com/2005/01/14/how-to-delete-a-global-temp-table/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>DATABASE ERROR CODE: 257 in SQL Server</title>
		<link>http://blogs.agilefaqs.com/2005/01/10/database-error-code-257-in-sql-server/</link>
		<comments>http://blogs.agilefaqs.com/2005/01/10/database-error-code-257-in-sql-server/#comments</comments>
		<pubDate>Mon, 10 Jan 2005 05:52:36 +0000</pubDate>
		<dc:creator>Naresh Jain</dc:creator>
				<category><![CDATA[Database]]></category>

		<guid isPermaLink="false">http://blogs.agilefaqs.com/?p=137</guid>
		<description><![CDATA[Of late, we have been getting the following error every now and then. We are using MS SQL Server 2000 and it&#8216;s JDBC drivers. DATABASE ERROR CODE : 257 11:58:18 [ ] WARN WEB DATABASE ERROR CODE : 257 11:58:18 [ ] ERROR &#8230; Read More]]></description>
			<content:encoded><![CDATA[<p>Of late, we have been getting the following error every now and then. We are using  MS SQL  Server 2000 and it&#8216;s  JDBC  drivers. </p>
<p>	  DATABASE ERROR CODE : 257<br />
11:58:18 [        ]  WARN   WEB     DATABASE ERROR CODE : 257<br />
11:58:18 [        ]  ERROR &#8230;
<div class="readMore"><a href="http://jroller.com/page/njain?entry=never_ending_issues_with_ms">Read More</a></div>
]]></content:encoded>
			<wfw:commentRss>http://blogs.agilefaqs.com/2005/01/10/database-error-code-257-in-sql-server/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to create a Temp Table in SQL Server using an EXEC statement?</title>
		<link>http://blogs.agilefaqs.com/2005/01/10/how-to-create-a-temp-table-in-sql-server-using-an-exec-statement/</link>
		<comments>http://blogs.agilefaqs.com/2005/01/10/how-to-create-a-temp-table-in-sql-server-using-an-exec-statement/#comments</comments>
		<pubDate>Mon, 10 Jan 2005 05:52:21 +0000</pubDate>
		<dc:creator>Naresh Jain</dc:creator>
				<category><![CDATA[Database]]></category>

		<guid isPermaLink="false">http://blogs.agilefaqs.com/?p=138</guid>
		<description><![CDATA[What happens when you try the following inside a SQL Server Strored Procedure? EXEC (&#8216;CREATE TABLE #TEMPTABLE&#8216;+&#8216;123&#8216;+&#8216;(firstColumn varchar(10), secondColumn varchar(20), thridColumn int)&#8216;) INSERT INTO &#8230; Read More]]></description>
			<content:encoded><![CDATA[<p>What happens when you try the following inside a  SQL  Server Strored Procedure? </p>
<p>	  EXEC  (&#8216;CREATE  TABLE  #TEMPTABLE&#8216;+&#8216;123&#8216;+&#8216;(firstColumn varchar(10), secondColumn varchar(20), thridColumn int)&#8216;)<br />
 INSERT INTO &#8230;
<div class="readMore"><a href="http://jroller.com/page/njain?entry=how_to_create_a_temp">Read More</a></div>
]]></content:encoded>
			<wfw:commentRss>http://blogs.agilefaqs.com/2005/01/10/how-to-create-a-temp-table-in-sql-server-using-an-exec-statement/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Truncating Transaction Log in SQL Server</title>
		<link>http://blogs.agilefaqs.com/2005/01/10/truncating-transaction-log-in-sql-server/</link>
		<comments>http://blogs.agilefaqs.com/2005/01/10/truncating-transaction-log-in-sql-server/#comments</comments>
		<pubDate>Mon, 10 Jan 2005 05:52:01 +0000</pubDate>
		<dc:creator>Naresh Jain</dc:creator>
				<category><![CDATA[Database]]></category>

		<guid isPermaLink="false">http://blogs.agilefaqs.com/?p=139</guid>
		<description><![CDATA[What does the transaction log contain? Transaction log contains log records which are necessary for recovering or restoring a database. What happens if these log records were never deleted from the transaction log? Every transaction log has a fixed size&#8230;. Read More]]></description>
			<content:encoded><![CDATA[<p>What does the transaction log contain?<br />
Transaction log contains log records which are necessary for recovering or restoring a database. </p>
<p>	 What happens if these log records were never deleted from the transaction log?<br />
Every transaction log has a fixed size&#8230;.
<div class="readMore"><a href="http://jroller.com/page/njain?entry=truncating_transaction_log_in_sql">Read More</a></div>
]]></content:encoded>
			<wfw:commentRss>http://blogs.agilefaqs.com/2005/01/10/truncating-transaction-log-in-sql-server/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

