<?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>TBNL &#187; mysql</title>
	<atom:link href="http://www.tibobeijen.nl/blog/tag/mysql/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.tibobeijen.nl</link>
	<description>...another view on the web and how it's built</description>
	<lastBuildDate>Wed, 06 Jul 2011 19:28:47 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Fixing mysqldump on Zend Server CE on OS X</title>
		<link>http://www.tibobeijen.nl/blog/2011/03/01/fixing-mysqldump-on-zend-server-ce-on-os-x/</link>
		<comments>http://www.tibobeijen.nl/blog/2011/03/01/fixing-mysqldump-on-zend-server-ce-on-os-x/#comments</comments>
		<pubDate>Tue, 01 Mar 2011 07:37:56 +0000</pubDate>
		<dc:creator>Tibo Beijen</dc:creator>
				<category><![CDATA[miscellaneous]]></category>
		<category><![CDATA[configuration]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[os x]]></category>
		<category><![CDATA[server administration]]></category>
		<category><![CDATA[zend server]]></category>

		<guid isPermaLink="false">http://www.tibobeijen.nl/?p=652</guid>
		<description><![CDATA[A while ago I installed Zend Server Community Edition on OS X which was pretty straightforward. It was only recently that I found out that, as opposed to mysql which worked fine, mysqldump didn&#8217;t work correctly and terminated with the error: mysqldump: Got error: 2002: Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2) [...]]]></description>
			<content:encoded><![CDATA[<p>A while ago I installed Zend Server Community Edition on OS X which was pretty straightforward. It was only recently that I found out that, as opposed to <code>mysql</code> which worked fine, <code>mysqldump</code> didn&#8217;t work correctly and terminated with the error:<br />
<code><br />
mysqldump: Got error: 2002: Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2) when trying to connect<br />
</code><br />
Inspecting the mysql configuration contained in <code>/usr/local/zend/mysql/data/my.cnf</code> confirmed that the section [client] showed the socket as returned by executing <code>SHOW VARIABLES;</code> from the mysql client: <code>/usr/local/zend/mysql/tmp/mysql.sock</code></p>
<p>Although it is possible to specify the socket by using mysqldump&#8217;s <code>--socket</code> switch, that doesn&#8217;t really seem a &#8216;solution&#8217;. </p>
<p>Apparently mysqldump, as opposed to the mysql client does not use the server-specific settings contained in <code>/usr/local/zend/mysql/data/my.cnf</code>. The comments in my.cnf state:</p>

<div class="wp_syntax"><div class="code"><pre class="ini" style="font-family:monospace;"># You can copy this file to
# /etc/my.cnf to set global options,
# mysql-data-dir/my.cnf to set server-specific options <span style="">&#40;</span>in this
# installation this directory is /usr/local/zend/mysql/data<span style="">&#41;</span> or
# ~/.my.cnf to set user-specific options.</pre></div></div>

<p>After copying <code>/usr/local/zend/mysql/data/my.cnf</code> to <code>/etc/my.cnf</code> mysqldump worked as expected.</p>
<p>In <code>/etc/my.cnf</code> I have included only the setting needed to get mysqldump running:</p>

<div class="wp_syntax"><div class="code"><pre class="ini" style="font-family:monospace;"># Specifying socket to use for mysql/mysqldump
# For other settings refer to /usr/local/zend/mysql/data/my.cnf
<span style="color: #000066; font-weight:bold;"><span style="">&#91;</span>client<span style="">&#93;</span></span>
<span style="color: #000099;">socket</span>      <span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;"> /usr/local/zend/mysql/tmp/mysql.sock</span></pre></div></div>

<p>Hope this saves anyone running into the same issue some time.</p>
<p><strong>Update</strong> (alternative solutions):<br />
As Joel Clermont pointed out it is also possible to create a symlink on the socket location expected by mysqldump to the real socket location. This can be done by executing:<br />
<code><br />
ln -s /usr/local/zend/mysql/tmp/mysql.sock /tmp/mysql.sock<br />
</code></p>
<p>Another possible approach is to create a symlink at <code>/etc/my.cnf</code> to <code>/usr/local/zend/mysql/data/my.cnf</code>. This has the downside that it requires loosening the default permissions (<code>drwxr-x---</code>) on the data folder by allowing &#8216;others&#8217; to enter it. Commands to execute:<br />
<code><br />
sudo chmod o+x /usr/local/zend/mysql/data<br />
sudo ln -s /usr/local/zend/mysql/data/my.cnf my.cnf<br />
</code><br />
Granting more permissions can be a security consideration but on most development setups this probably won&#8217;t be an issue.</p>
<p>Additional info about Zend Server CE on OS X:</p>
<ul>
<li><a href="http://files.zend.com/help/Zend-Server-Community-Edition/zend-server-community-edition.htm">Zend Server CE Documentation</a></li>
<li><a href="http://akrabat.com/php/some-notes-on-zend-server-ce-for-mac-os-x/">Rob Allen: Some notes on Zend Server CE for Mac OS X</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.tibobeijen.nl/blog/2011/03/01/fixing-mysqldump-on-zend-server-ce-on-os-x/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>SQL injection &amp; the Kaspersky hack</title>
		<link>http://www.tibobeijen.nl/blog/2009/02/11/sql_injection-and-the-kaspersky-hack/</link>
		<comments>http://www.tibobeijen.nl/blog/2009/02/11/sql_injection-and-the-kaspersky-hack/#comments</comments>
		<pubDate>Wed, 11 Feb 2009 18:38:50 +0000</pubDate>
		<dc:creator>Tibo Beijen</dc:creator>
				<category><![CDATA[miscellaneous]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[security]]></category>
		<category><![CDATA[sql injection]]></category>

		<guid isPermaLink="false">http://www.tibobeijen.nl/?p=137</guid>
		<description><![CDATA[Last week I read an article on webwereld titled &#8216;2008 was year of the SQL injection attack&#8216;. It was based on an article with the same title on networkworld.com. Apparently SQL injection has taken over the lead from XSS. Not surprisingly the first user-comment stated that almost 100% of the exploits were certainly in PHP [...]]]></description>
			<content:encoded><![CDATA[<p>Last week I read an article on webwereld titled &#8216;<a href="http://webwereld.nl/article/comments/id/54694">2008 was year of the SQL injection attack</a>&#8216;. It was based on an <a href="http://www.networkworld.com/news/2009/020209-sql-injection-attack.html">article with the same title on networkworld.com</a>. Apparently SQL injection has taken over the lead from XSS. Not surprisingly the first user-comment stated that almost 100% of the exploits were certainly in PHP applications written by would-be programmers. With things so obvious it&#8217;s of course unneccessary to provide factual data backing up such a statement. So, nothing to win in that discussion. Three days ago news came that <a href="http://www.theregister.co.uk/2009/02/08/kaspersky_compromise_report/">a customer database of Kaspersky was hacked</a>. By using SQL injection. On <a href="http://usa.kaspersky.com/about-us/news-press-releases.php?smnr_id=900000208">a PHP website</a>. Could commenter X be right?<br />
<span id="more-137"></span><br />
It <em>is</em> true that PHP allows novice as well as experienced programmers to achieve &#8216;what they want&#8217;. And the novice might adopt some very bad practices. But does that make PHP an insecure programming language? Compare it to driving a car. Yes, you can drive around like a maniac and wreak havoc on the unaware. But does that make a car an unsecure vehicle?  The PHP platform offers enough techniques to rule out SQL injection attacks:</p>
<ul>
<li>Prepared statements. There&#8217;s no need to concat potentially harmful data in SQL statements. Provide them as a parameter when executung a prepared statement. More efficient too.</li>
<li>ORM. If you think SQL should be behind an abstraction layer, you can do so. <a href="http://propel.phpdb.org/">Propel</a> and <a href="http://www.doctrine-project.org/">Doctrine</a> are the best known solutions for PHP.</li>
<li>Well structured programming. If, for some reason, you want to build queries the old way you can force upon yourself (or your team) some good practices. See example below.</li>
</ul>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$dataTainted</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'un'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'un'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$dataTainted</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'pw'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'pw'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// escape all array values using a custom function of some sort</span>
<span style="color: #000088;">$dataSafe</span> <span style="color: #339933;">=</span> mysqlEscapeValues<span style="color: #009900;">&#40;</span><span style="color: #000088;">$dataTainted</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$query</span> <span style="color: #339933;">=</span> <span style="color: #0000cc; font-style: italic;">&lt;&lt;&lt;SQL
SELECT
  *
FROM
  users
WHERE
  un = &quot;{$dataSafe['un']}&quot;
AND
  pw = SHA1(&quot;{$dataSafe['pw']}&quot;)
SQL</span><span style="color: #339933;">;</span></pre></div></div>

<p>And that&#8217;s just the coding part of the story. In the area of application design a lot can be done to minimize the consequences of an exploit. For example, different database users can be set up that have different levels of access. Only parts of a website needing customer data then use the credentials that do provide such access.</p>
<p>So, for PHP there are good practices and solutions aplenty. For more information on SQL injection one can start at <a href="http://www.owasp.org/index.php/Guide_to_SQL_Injection">OWASP</a> or <a href="http://en.wikipedia.org/wiki/SQL_injection#Real-world_examples">Wikipedia</a>. And finally, the subject isn&#8217;t non-existent in <a href="http://msdn.microsoft.com/en-us/magazine/cc163917.aspx">.NET</a> and <a href="http://kb.adobe.com/selfservice/viewContent.do?externalId=585ac720">JSP</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.tibobeijen.nl/blog/2009/02/11/sql_injection-and-the-kaspersky-hack/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

