<?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>The Thinking Lemur &#187; Databases</title>
	<atom:link href="http://thinkinglemur.com/index.php/category/thinking/databases/feed/" rel="self" type="application/rss+xml" />
	<link>http://thinkinglemur.com</link>
	<description>from the mind of Donnie Bachan</description>
	<lastBuildDate>Sun, 11 Jul 2010 01:36:05 +0000</lastBuildDate>
	
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>LOAD DATA INFILE and FILE Permissions on MySQL</title>
		<link>http://thinkinglemur.com/index.php/2009/06/load-data-infile-and-file-permissions-on-mysql/</link>
		<comments>http://thinkinglemur.com/index.php/2009/06/load-data-infile-and-file-permissions-on-mysql/#comments</comments>
		<pubDate>Mon, 22 Jun 2009 13:27:18 +0000</pubDate>
		<dc:creator>Donnie Bachan</dc:creator>
				<category><![CDATA[Databases]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[SQL]]></category>

		<guid isPermaLink="false">http://thinkinglemur.com/?p=234</guid>
		<description><![CDATA[I ran into an issue running the LOAD DATA INFILE command from a PHP script the other day. When I logged in as ROOT and executed the script on MySQL Query Browser it worked like a charm. However, when I executed the script from PHP as another use with only SELECT, INSERT, UPDATE and DELETE [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;"><a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fthinkinglemur.com%2Findex.php%2F2009%2F06%2Fload-data-infile-and-file-permissions-on-mysql%2F"><img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fthinkinglemur.com%2Findex.php%2F2009%2F06%2Fload-data-infile-and-file-permissions-on-mysql%2F" height="61" width="51" /></a></div><p>I ran into an issue running the LOAD DATA INFILE command from a PHP script the other day. When I logged in as ROOT and executed the script on MySQL Query Browser it worked like a charm. However, when I executed the script from PHP as another use with only SELECT, INSERT, UPDATE and DELETE premission the script failed saying the user does not have enough rights to perform the operation. According to the documentation if the client and server are on the same machine you use the LOAD DATA INFILE form to bulk insert data. However this requires that FILE permission be granted to the user, which is obviously a possible security risk. There does exists a simple work around to this however use the following form of the statement:</p>
<blockquote><p>LOAD DATA LOCAL INFILE &#8230;</p></blockquote>
<p>This form of the statement should be used when the client and server exists on different machines but works just as well if they are on the same machine and removes the need for the FILE permission.</p>
]]></content:encoded>
			<wfw:commentRss>http://thinkinglemur.com/index.php/2009/06/load-data-infile-and-file-permissions-on-mysql/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Re-installation of MySQL 5.x</title>
		<link>http://thinkinglemur.com/index.php/2009/05/re-installation-of-mysql-5x/</link>
		<comments>http://thinkinglemur.com/index.php/2009/05/re-installation-of-mysql-5x/#comments</comments>
		<pubDate>Wed, 06 May 2009 13:20:28 +0000</pubDate>
		<dc:creator>Donnie Bachan</dc:creator>
				<category><![CDATA[Databases]]></category>
		<category><![CDATA[MySQL]]></category>

		<guid isPermaLink="false">http://thinkinglemur.com/?p=230</guid>
		<description><![CDATA[A friend of mine recently had an issue while installing MySQL 5.1.34 on a Windows 2003 R2 system using the binary installer. All seemed to have gone well with the install except that when it was done he couldn&#8217;t log into the database as root. Obviously, we thought that the password was wrong, so we [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;"><a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fthinkinglemur.com%2Findex.php%2F2009%2F05%2Fre-installation-of-mysql-5x%2F"><img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fthinkinglemur.com%2Findex.php%2F2009%2F05%2Fre-installation-of-mysql-5x%2F" height="61" width="51" /></a></div><p>A friend of mine recently had an issue while installing MySQL 5.1.34 on a Windows 2003 R2 system using the binary installer. All seemed to have gone well with the install except that when it was done he couldn&#8217;t log into the database as root. Obviously, we thought that the password was wrong, so we tried to reset it using mysqladmin using the command:</p>
<blockquote><p>c:\&gt; mysqladmin -u root flush-privileges password &lt;new-password&gt;</p></blockquote>
<p>However this did not work, even after restarting with the &#8211;skip-grant-tables option set. So the next course of action was to re-install. The current installation was removed using the uninstall option and the mySQL folder created on the C:\Program Files folder was junked. </p>
<p>The re-install started with no problems but curiously remembered all the previous settings (sign of problems to come!). The install completed but configuration failed with the wizard unable to apply security settings because the password was incorrect. Apparently it seems that the password is stored somewhere that was not removed in the previous uninstall.</p>
<p>In the end the following steps worked for completely removing and re-installing:</p>
<ol>
<li>Perform un-install using wizard</li>
<li>Manually remove the service if still installed</li>
<li>Delete folder C:\Program Files\MySQL</li>
<li>Delete C:\Windows\my.ini</li>
<li>Delete the MySQL folder in Application Data. The actual Application Data folder will depend on the user performing the installation</li>
<li>Re-install</li>
</ol>
]]></content:encoded>
			<wfw:commentRss>http://thinkinglemur.com/index.php/2009/05/re-installation-of-mysql-5x/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>SQL Server 2005 Deadlock Tracking</title>
		<link>http://thinkinglemur.com/index.php/2009/04/sql-server-2005-deadlock-tracking/</link>
		<comments>http://thinkinglemur.com/index.php/2009/04/sql-server-2005-deadlock-tracking/#comments</comments>
		<pubDate>Tue, 07 Apr 2009 09:14:29 +0000</pubDate>
		<dc:creator>Donnie Bachan</dc:creator>
				<category><![CDATA[Databases]]></category>
		<category><![CDATA[SQL Server]]></category>

		<guid isPermaLink="false">http://thinkinglemur.com/?p=218</guid>
		<description><![CDATA[This is a very useful article for anyone experiencing deadlock issues with SQL Server 2005.
http://www.simple-talk.com/sql/learn-sql-server/how-to-track-down-deadlocks-using-sql-server-2005-profiler/
I made use of this while tracking down the cause of the following error:
Transaction (Process ID 97) was deadlocked on lock &#124; communication buffer resources with another process and has been chosen as the deadlock victim. Rerun the transaction.
When using Profiler [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;"><a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fthinkinglemur.com%2Findex.php%2F2009%2F04%2Fsql-server-2005-deadlock-tracking%2F"><img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fthinkinglemur.com%2Findex.php%2F2009%2F04%2Fsql-server-2005-deadlock-tracking%2F" height="61" width="51" /></a></div><p>This is a very useful article for anyone experiencing deadlock issues with SQL Server 2005.</p>
<blockquote><p><a href="http://www.simple-talk.com/sql/learn-sql-server/how-to-track-down-deadlocks-using-sql-server-2005-profiler/">http://www.simple-talk.com/sql/learn-sql-server/how-to-track-down-deadlocks-using-sql-server-2005-profiler/</a></p></blockquote>
<p>I made use of this while tracking down the cause of the following error:</p>
<blockquote><p>Transaction (Process ID 97) was deadlocked on lock | communication buffer resources with another process and has been chosen as the deadlock victim. Rerun the transaction.</p></blockquote>
<p>When using Profiler it is important that you don&#8217;t set too many items on trace in a production environment, this can cause your database performance to degrade dramatically.</p>
]]></content:encoded>
			<wfw:commentRss>http://thinkinglemur.com/index.php/2009/04/sql-server-2005-deadlock-tracking/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Web data security paranoia</title>
		<link>http://thinkinglemur.com/index.php/2009/02/web-data-security-paranoia/</link>
		<comments>http://thinkinglemur.com/index.php/2009/02/web-data-security-paranoia/#comments</comments>
		<pubDate>Mon, 23 Feb 2009 13:41:48 +0000</pubDate>
		<dc:creator>Donnie Bachan</dc:creator>
				<category><![CDATA[ColdFusion]]></category>
		<category><![CDATA[Databases]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Security]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[encryption]]></category>
		<category><![CDATA[SQL Server]]></category>

		<guid isPermaLink="false">http://thinkinglemur.com/?p=174</guid>
		<description><![CDATA[My recent experiences with several hacking attacks has made me think more about application and data security on the web. In today&#8217;s world nothing can be taken for granted and security should be of the highest concern, no mater how simple you think your application or trivial the data you store. Many web applications are [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;"><a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fthinkinglemur.com%2Findex.php%2F2009%2F02%2Fweb-data-security-paranoia%2F"><img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fthinkinglemur.com%2Findex.php%2F2009%2F02%2Fweb-data-security-paranoia%2F" height="61" width="51" /></a></div><p>My recent experiences with several hacking attacks has made me think more about application and data security on the web. In today&#8217;s world nothing can be taken for granted and security should be of the highest concern, no mater how simple you think your application or trivial the data you store. Many web applications are hosted on shared servers or virtual private servers where the first line of defense is often left to the hosting provider. The first line of defense is perimeter security such as hardware firewalls and other network related prevention. You are also at the hands of the hosting provider when it comes to software security, that is, your operating system, web server, application servers and scripting languages and ftp patches.</p>
<p>The first thing that and good security plan should have is a proper review of these basic things. Contact your hosting provider and find out about patch management and other security options that may be their responsibility. If you manage your own server then you need to be aware of firewalls (software or hardware), antivirus, patch management and user security.</p>
<p>Now, on to your web application security. In my previous article on <a href="http://thinkinglemur.com/index.php/2009/02/preventing-sql-injection-attacks-in-coldfusion/">preventing sql injection attacks in coldfusion</a>  there are quite a few tips for securing the applications. One other place developers tend to ignore is the transmission of data to and storage of data in the database. So let&#8217;s look at some of the options for securing data.</p>
<p><strong>Database access:</strong></p>
<p>If your budget supports it, the first thing that should be implemented would be to have your database on a separate physical machine from your application server or public web server. This has two positive effects. Firstly, moving the database server to another machine will take the load off the web server or application server which can only be a good thing. Secondly, you public web server would be the first machine to be attacked, thus if a breach were to occur having the database on another machine would add some level of defense.</p>
<p>Ensure that the web application database user has the bare minimum rights to the database. That is, if the web application has no need to add tables or drop tables then the user should not have CREATE or DROP rights. Ensure, under no circumstances that your web application uses ROOT, SA or any other master login to access your database. Create a separate user for each application and give it the required rights.</p>
<p>One other thing I like to do is limit remote access to the database, if you can get SSH/RDP access to the server limit that to specific IP addresses. This causes remote administration to be a pain but the security benefits outweight the inconvenience.</p>
<p> </p>
<p><strong>Data storage:</strong></p>
<p>Now, once you have the correct rights on your database and secured it from web access the next step would be to secure the actual data being stored. You will want to ensure that the forms that submit information are secured with a valid strong SSL certificate. Now, you may not be interested in using SSL encryption for all forms on  your site but it is a good practice to secure forms such as registration, login, shopping carts and checkout forms. Basically, any form that has any user information should be secured.</p>
<p>This same thinking should extend to storing the data in the database. Many developers encrypt passwords and store them in the database, but I think other things like usernames, email addresses and any other information that can potential be regarded as sensitive information should be encrypted and stored in the database. There are two options for this. Let the database encrypt the data for you or let your application encrypt the data before it is inserted in the database.</p>
<p>In SQL Server 2005, you can achieve this using some special functions. You can read more about this method in the following articles:</p>
<blockquote><p><a href="http://www.sql-server-performance.com/articles/dev/encryption_2005_1_p1.aspx">http://www.sql-server-performance.com/articles/dev/encryption_2005_1_p1.aspx</a></p>
<p><a href="http://www.sql-server-performance.com/articles/dev/encryption_2005_2_p1.aspx">http://www.sql-server-performance.com/articles/dev/encryption_2005_2_p1.aspx</a></p></blockquote>
<p>Other popular databases would have similar features.</p>
<p>The other option would be to encrypt the data before storing it in the database and then decrypting it when it needs to be used. In ColdFusion, this can be achieved using the encrypt and decrypt functions. These functions allow you to choose and encryption algorithm (SHA1, Blowfish etc) and a security key. The major drawback to this method is speed. This would slow down the communication of data between the web application and the user, however I think this is a fair trade off for the security concious.</p>
]]></content:encoded>
			<wfw:commentRss>http://thinkinglemur.com/index.php/2009/02/web-data-security-paranoia/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Preventing SQL Injection attacks in ColdFusion</title>
		<link>http://thinkinglemur.com/index.php/2009/02/preventing-sql-injection-attacks-in-coldfusion/</link>
		<comments>http://thinkinglemur.com/index.php/2009/02/preventing-sql-injection-attacks-in-coldfusion/#comments</comments>
		<pubDate>Tue, 17 Feb 2009 14:17:32 +0000</pubDate>
		<dc:creator>Donnie Bachan</dc:creator>
				<category><![CDATA[ColdFusion]]></category>
		<category><![CDATA[Databases]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Security]]></category>

		<guid isPermaLink="false">http://thinkinglemur.com/?p=143</guid>
		<description><![CDATA[This is an article I came across on Ben Forta&#8217;s blog. This gives some very good tips on preventing SQL  injection attacks and provides some excellent best practices.
 http://www.adobe.com/devnet/coldfusion/articles/sql_injection.html
When I took up my current position we had to do a vulnerability scan to become PCI compliant and well we originally failed horribly. After much work we [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;"><a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fthinkinglemur.com%2Findex.php%2F2009%2F02%2Fpreventing-sql-injection-attacks-in-coldfusion%2F"><img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fthinkinglemur.com%2Findex.php%2F2009%2F02%2Fpreventing-sql-injection-attacks-in-coldfusion%2F" height="61" width="51" /></a></div><p>This is an article I came across on <a href="http://www.forta.com">Ben Forta&#8217;s blog</a>. This gives some very good tips on preventing SQL  injection attacks and provides some excellent best practices.</p>
<blockquote><p> <a href="http://www.adobe.com/devnet/coldfusion/articles/sql_injection.html">http://www.adobe.com/devnet/coldfusion/articles/sql_injection.html</a></p></blockquote>
<p>When I took up my current position we had to do a vulnerability scan to become PCI compliant and well we originally failed horribly. After much work we got it compliant and fixed all of the security holes identified. The article above gives some ColdFusion specific items but also defines some techniques that can be applied to other languages. A few things that are of note are:</p>
<ul>
<li>Database user privileges</li>
<li>Use of stored procedures</li>
<li>Use of dynamic table names</li>
</ul>
<p>These three points are usually overlooked by the average developer and should really be implemented. </p>
<p> </p>
<p>Database User Access:</p>
<p>Only give the user the minimum rights required to perform the task. So if your user only needs to perform select and update operations they should not have delete, create or other rights.</p>
<p> </p>
<p>Stored Procedures:</p>
<p>Stored procedures provide a very good way to abstract and hide database logic from your code. This is a problem with many of the frameworks that use Active Record patterns like Rails and CakePHP or ORM systems like Reactor in ColdFusion but stored procedures can provide significant performance improvements as well as having security benefits.</p>
<p> </p>
<p>Dynamic Table Names:</p>
<p>By prefixing your database tables with a custom string, you can build queries that use a dynamic string for accessing the table information instead of hardcoding the table name. This is another good idea since many systems use generic table names like users, categories, groups etc which can be easily guessed.</p>
<p> </p>
<p>It is very important to analyse every section of code and perform a security audit ensuring that all forms are protected since this is the first place that attackers target.</p>
]]></content:encoded>
			<wfw:commentRss>http://thinkinglemur.com/index.php/2009/02/preventing-sql-injection-attacks-in-coldfusion/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>MySQL 5 timestamp error in ColdFusion 8</title>
		<link>http://thinkinglemur.com/index.php/2009/02/mysql-5-timestamp-error-in-coldfusion-8/</link>
		<comments>http://thinkinglemur.com/index.php/2009/02/mysql-5-timestamp-error-in-coldfusion-8/#comments</comments>
		<pubDate>Fri, 06 Feb 2009 23:55:02 +0000</pubDate>
		<dc:creator>Donnie Bachan</dc:creator>
				<category><![CDATA[ColdFusion]]></category>
		<category><![CDATA[Databases]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[SQL]]></category>

		<guid isPermaLink="false">http://thinkinglemur.com/?p=124</guid>
		<description><![CDATA[Scenario:
Query grabs user data from MySQL 5 database using the built in MySQL 4/5 driver in ColdFusion 8 on a Windows 2003 Server.
 
Problem:
Cannot convert value &#8216;0000-00-00 00:00:00&#8242; from column 10 to TIMESTAMP error returned on execution.
 
Analysis:
After a quick search on Google, it appears that the default behaviour for the Connector J MySQL driver is to [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;"><a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fthinkinglemur.com%2Findex.php%2F2009%2F02%2Fmysql-5-timestamp-error-in-coldfusion-8%2F"><img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fthinkinglemur.com%2Findex.php%2F2009%2F02%2Fmysql-5-timestamp-error-in-coldfusion-8%2F" height="61" width="51" /></a></div><p><strong>Scenario:</strong></p>
<p>Query grabs user data from MySQL 5 database using the built in MySQL 4/5 driver in ColdFusion 8 on a Windows 2003 Server.</p>
<p> </p>
<p><strong>Problem:</strong></p>
<p>Cannot convert value &#8216;0000-00-00 00:00:00&#8242; from column 10 to TIMESTAMP error returned on execution.</p>
<p> </p>
<p><strong>Analysis:</strong></p>
<p>After a quick search on Google, it appears that the default behaviour for the Connector J MySQL driver is to not allow zero date values. A specific value must be included in the connect string to overide this value.</p>
<p> </p>
<p><strong>Resolution:</strong></p>
<p>Include the zeroDateTimeBehavior=convertToNull value in the connect string. In ColdFusion the instructions are:</p>
<p> </p>
<ul>
<li>Go to Data Sources in the ColdFusion Administrator</li>
<li>Select the MySQL 4/5 datasource and click the Show Advanced Settings button</li>
<li>In the Connect String box append the following: zeroDateTimeBehavior=convertToNull </li>
</ul>
<p>Note: if there is already a connect string add an ampersand to the end of the existing string before adding the new value. For example if the connect string was set to:</p>
<blockquote><p>useUnicode=true&amp;characterEncoding=iso-8859-1</p></blockquote>
<p>The new string would look like:</p>
<blockquote><p>useUnicode=true&amp;characterEncoding=iso-8859-1&amp;zeroDateTimeBehavior=convertToNull</p></blockquote>
]]></content:encoded>
			<wfw:commentRss>http://thinkinglemur.com/index.php/2009/02/mysql-5-timestamp-error-in-coldfusion-8/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
