<?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>Paul Maunders &#124; Web log &#187; mysql</title>
	<atom:link href="http://www.pyrosoft.co.uk/blog/category/mysql/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.pyrosoft.co.uk/blog</link>
	<description>Economics, Business, Telecoms, Tech and Gadgets</description>
	<lastBuildDate>Tue, 22 Jun 2010 21:05:22 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>MySQL one database versus multiple databases</title>
		<link>http://www.pyrosoft.co.uk/blog/2009/05/10/mysql-one-database-versus-multiple-databases/</link>
		<comments>http://www.pyrosoft.co.uk/blog/2009/05/10/mysql-one-database-versus-multiple-databases/#comments</comments>
		<pubDate>Sun, 10 May 2009 17:13:24 +0000</pubDate>
		<dc:creator>Paul Maunders</dc:creator>
				<category><![CDATA[mysql]]></category>

		<guid isPermaLink="false">http://www.pyrosoft.co.uk/blog/?p=922</guid>
		<description><![CDATA[When designing an application &#8211; should you put each customer in a separate database or keep them all in one large central database? When it came to start work on our new Clear Books accounting software last year, we had to make a fundamental database design choice between using a single database for all clients, [...]]]></description>
			<content:encoded><![CDATA[<p><em>When designing an application &#8211; should you put each customer in a separate database or keep them all in one large central database?</em></p>
<p>When it came to start work on our new Clear Books accounting software last year, we had to make a fundamental database design choice between using a single database for all clients, or having a separate database for each one.</p>
<p>Since there was going to be a fairly large amount of data for each client, we decided to go for the latter, and one year on &#8211; I am very happy with our decision.</p>
<p><strong>Advantages</strong></p>
<ul>
<li>Easier to balance load. Since each client is in a separate database, it is relatively easy to move them between database servers.</li>
<li>Faster. One client&#8217;s tables being locked won&#8217;t affect another clients. Indexes are smaller. If MySQL has to do a row scan (let&#8217;s hope it doesn&#8217;t!), it&#8217;ll be faster.</li>
<li>MyISAM rsync backups will be faster.</li>
<li>Easier to clone a clients database for testing purposes (just simply copy the whole db, no need to write a special script to extract their data).</li>
</ul>
<p><strong>Disadvantages</strong></p>
<ul>
<li>Upgrading the database is more complicated, as you have to add new fields to each client database, rather than just once globally. If you are successful you could be dealing with thousands of databases, and so an upgrade script is definitely needed. However, this is also a blessing in disguise as it allows you to test upgrades on a small set of databases before rolling them out generally.</li>
<li>More complicated to implement in general.</li>
</ul>
<p>I think the ultimate decision would come down to how much data your store for each client. If it&#8217;s a fair amount, then I think separate databases is worth the extra development effort.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.pyrosoft.co.uk/blog/2009/05/10/mysql-one-database-versus-multiple-databases/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>PHP Web Application Security</title>
		<link>http://www.pyrosoft.co.uk/blog/2009/02/18/php-web-application-security/</link>
		<comments>http://www.pyrosoft.co.uk/blog/2009/02/18/php-web-application-security/#comments</comments>
		<pubDate>Wed, 18 Feb 2009 00:25:24 +0000</pubDate>
		<dc:creator>Paul Maunders</dc:creator>
				<category><![CDATA[mysql]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[penetration testing]]></category>
		<category><![CDATA[security]]></category>

		<guid isPermaLink="false">http://www.pyrosoft.co.uk/blog/?p=809</guid>
		<description><![CDATA[Here are some tips to help you think more about security when developing a web app.  Buy a good book on the subject, such as Securing PHP Web Applications and implement what you learn in your code. Read through Web Application Security section on of the SANS Institute 2007 top 20 security risks. There are some useful [...]]]></description>
			<content:encoded><![CDATA[<p>Here are some tips to help you think more about security when developing a web app. </p>
<ol>
<li>Buy a good book on the subject, such as <a href="http://www.amazon.com/Securing-PHP-Applications-Mere-Mortals/dp/0321534344">Securing PHP Web Applications</a> and implement what you learn in your code.</li>
<li>Read through <a href="http://www.sans.org/top20/#s1">Web Application Security</a> section on of the SANS Institute 2007 top 20 security risks. There are some useful tips on securing PHP in particular. 
<ul>
<li>Check PHP configuration settings:
<ul>
<li>Turn register_globals off, use super globals such as $_GET instead (from PHP 4.2.0 this is the default).</li>
<li>Turn allow_url_fopen off (unless you really need it).</li>
<li>Disable magic_quotes.</li>
<li>Configure open_basedir for each site to restrict access from PHP scripts to certain directories.</li>
<li>Consider running <a href="http://www.seaoffire.net/fcgi-faq.html">PHP with FastCGi</a> instead of mod_php</li>
</ul>
</li>
<li>Use best practices when developing:
<ul>
<li><strong>ALWAYS validate user input!</strong> This is probably the most important point in the entire list. There are many nasty bots and spiders going round the web trying to break into your site, and the most common way in is through your web forms. There are various validation libraries out there to make your life easier  (e.g. <a href="http://pear.php.net/package/Validate">PEAR Validate</a>, <a href="http://framework.zend.com/manual/en/zend.filter.input.html">Zend Filter Input</a>)- use them!</li>
<li>Avoid SQL injections. If you validate user input correctly, then this should help you avoid SQL injection vulnerabilities. To be doubly safe you could use a database abstraction layer, that if used correctly with prepare statements, will automatically escape user input data. Check out <a href="http://uk3.php.net/manual/en/pdo.prepare.php">PDO</a> and <a href="http://framework.zend.com/manual/en/zend.db.html">Zend DB</a>.</li>
<li>Avoid XSS attacks. An XSS attack is where malicious users are able to inject their own code in to pages on your site that may be viewed by other users. You could <a href="http://uk3.php.net/strip-tags">strip tags</a> from user input, and encode <a href="http://uk3.php.net/htmlentities">html entities</a> in any plain text being output.</li>
<li>Don&#8217;t transmit passwords and other secret information over plain text, submit to a secure URL.</li>
<li>Be careful when allowing uploads. Check the file types, and only allow files you expect. Resample uploaded images in case there is any hidden code inside.</li>
<li>Use sessions instead of cookies, unless you really need the persistence of a cookie. Sessions are temporary and keep everything except the session ID hidden from the user&#8217;s machine.</li>
<li>Peer review your code. Get another developer to look through it, two heads are better than one!</li>
</ul>
</li>
</ul>
</li>
<li>Download the <a href="http://wapiti.sourceforge.net/">Wapiti</a> and <a href="http://grendel-scan.com/">Grendel Scan</a> web application vulnerability scanning tools and run them on your sites.</li>
</ol>
<p>This is of course an overly simple list, and it can&#8217;t protect against things like logic flaws, but at least &#8211; if you were wondering where to start then I hope it will give you some useful inspiration!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.pyrosoft.co.uk/blog/2009/02/18/php-web-application-security/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>A script to reset the MySQL root password</title>
		<link>http://www.pyrosoft.co.uk/blog/2008/12/27/resetting-the-mysql-root-password/</link>
		<comments>http://www.pyrosoft.co.uk/blog/2008/12/27/resetting-the-mysql-root-password/#comments</comments>
		<pubDate>Sat, 27 Dec 2008 14:19:08 +0000</pubDate>
		<dc:creator>Paul Maunders</dc:creator>
				<category><![CDATA[linux]]></category>
		<category><![CDATA[mysql]]></category>

		<guid isPermaLink="false">http://www.pyrosoft.co.uk/blog/?p=568</guid>
		<description><![CDATA[It&#8217;s a pain if you ever forget your MySQL root password. Fortunately it&#8217;s a fairly straightforward process to reset it, here&#8217;s how: pkill -9 mysqld; echo &#34;UPDATE mysql.user SET Password=PASSWORD('MyNewPass') WHERE User='root'; FLUSH PRIVILEGES;&#34; &#38;gt; /tmp/reset-pass.sql mysqld_safe --init-file=/tmp/reset-pass.sql &#38;amp; sleep 10 pkill -9 mysqld; A bash script to reset the mysql root password To make [...]]]></description>
			<content:encoded><![CDATA[<p>It&#8217;s a pain if you ever forget your MySQL root password. Fortunately it&#8217;s a fairly straightforward process to reset it, here&#8217;s how:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">pkill <span style="color: #660033;">-9</span> mysqld;
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;UPDATE mysql.user SET Password=PASSWORD('MyNewPass') WHERE User='root';
FLUSH PRIVILEGES;&quot;</span> <span style="color: #000000; font-weight: bold;">&amp;</span>gt; <span style="color: #000000; font-weight: bold;">/</span>tmp<span style="color: #000000; font-weight: bold;">/</span>reset-pass.sql
mysqld_safe <span style="color: #660033;">--init-file</span>=<span style="color: #000000; font-weight: bold;">/</span>tmp<span style="color: #000000; font-weight: bold;">/</span>reset-pass.sql <span style="color: #000000; font-weight: bold;">&amp;</span>amp;
<span style="color: #c20cb9; font-weight: bold;">sleep</span> <span style="color: #000000;">10</span>
pkill <span style="color: #660033;">-9</span> mysqld;</pre></div></div>

<p><strong>A bash script to reset the mysql root password</strong></p>
<p>To make the process easier, I&#8217;ve wrapped these commands up in a script and put it on our open source respository here:</p>
<p><a href="http://svn.fubra.com/hosting/mysql-reset-root-password/trunk/mysql-reset-root-password.sh">mysql_reset_root_password.sh script</a></p>
<p>Update: This script has been improved with Andy&#8217;s suggestion in the comments,  which is a simpler and more secure method.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">killall</span> <span style="color: #660033;">-15</span> mysqld
<span style="color: #c20cb9; font-weight: bold;">read</span> <span style="color: #660033;">-s</span> <span style="color: #660033;">-p</span> <span style="color: #ff0000;">'Enter a new root password: '</span> MYSQL_ROOT_PASSWORD
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;UPDATE mysql.user SET Password=PASSWORD('<span style="color: #007800;">$MYSQL_ROOT_PASSWORD</span>') WHERE User='root';&quot;</span> <span style="color: #000000; font-weight: bold;">|</span> mysqld <span style="color: #660033;">--bootstrap</span></pre></div></div>

<div><span><br />
</span></div>
]]></content:encoded>
			<wfw:commentRss>http://www.pyrosoft.co.uk/blog/2008/12/27/resetting-the-mysql-root-password/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Running mysqldump via ssh (direct host to host copy)</title>
		<link>http://www.pyrosoft.co.uk/blog/2008/10/03/running-mysqldump-via-ssh-direct-host-to-host-copy/</link>
		<comments>http://www.pyrosoft.co.uk/blog/2008/10/03/running-mysqldump-via-ssh-direct-host-to-host-copy/#comments</comments>
		<pubDate>Fri, 03 Oct 2008 12:52:19 +0000</pubDate>
		<dc:creator>Paul Maunders</dc:creator>
				<category><![CDATA[linux]]></category>
		<category><![CDATA[mysql]]></category>

		<guid isPermaLink="false">http://www.pyrosoft.co.uk/blog/?p=430</guid>
		<description><![CDATA[In order to run a mysqldump from one host to another over SSH you can run: mysqldump dbname &#124; ssh root@remotehost.com "mysql -D dbname" This will pipe the output of mysqldump directly to the ssh connection which is running MySQL at the other end and receiving the mysqldump from standard input.]]></description>
			<content:encoded><![CDATA[<p>In order to run a mysqldump from one host to another over SSH you can run:<br />
<code><br />
mysqldump dbname | ssh root@remotehost.com "mysql -D dbname"</code><br />
This will pipe the output of mysqldump directly to the ssh connection which is running MySQL at the other end and receiving the mysqldump from standard input.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.pyrosoft.co.uk/blog/2008/10/03/running-mysqldump-via-ssh-direct-host-to-host-copy/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Getting Apache, PHP and MySQL to work on Leopard</title>
		<link>http://www.pyrosoft.co.uk/blog/2008/09/16/getting-apache-php-and-mysql-to-work-on-leopard/</link>
		<comments>http://www.pyrosoft.co.uk/blog/2008/09/16/getting-apache-php-and-mysql-to-work-on-leopard/#comments</comments>
		<pubDate>Tue, 16 Sep 2008 09:44:59 +0000</pubDate>
		<dc:creator>Paul Maunders</dc:creator>
				<category><![CDATA[apple]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://www.pyrosoft.co.uk/blog/?p=419</guid>
		<description><![CDATA[Enabling PHP If you have upgraded from Tiger, you may need to complete this step to get Leopard&#8217;s version of Apache to work with UserDir (otherwise ignore this bit): Copy your old userdir configurations from /etc/httpd/users/ to /etc/apache2/users/ PHP is normally disabled by the default Apache configuration, so you will need to load up a [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Enabling PHP</strong></p>
<p>If you have upgraded from Tiger, you may need to complete this step to get Leopard&#8217;s version of Apache to work with UserDir (otherwise ignore this bit):</p>
<ul>
<li>Copy your old userdir configurations from /etc/httpd/users/ to /etc/apache2/users/</li>
</ul>
<p>PHP is normally disabled by the default Apache configuration, so you will need to load up a text editor and then:</p>
<ul>
<li>Uncomment <em>LoadModule php5_module        libexec/apache2/libphp5.so</em> in /etc/apache2/httpd.conf</li>
</ul>
<p>Once you&#8217;ve saved this, you&#8217;ll need to restart apache. The easiest way to do this is to go to System Preferences &gt; Sharing and to turn Web sharing off then on again.</p>
<p><strong>Installing MySQL</strong></p>
<p>To install MySQL, just follow these steps:</p>
<ul>
<li>Download the MySQL OS X disk image from a <a href="http://www.mirrorservice.org/sites/ftp.mysql.com/downloads/mysql/5.1.html#macosx-dmg">MySQL mirror</a></li>
<li>Mount the image, and install the main package, the startup item package, and then the preferences pane</li>
<li>Add the mysql bin folder to your path:
<pre>sudo echo 'export PATH=$PATH:/usr/local/mysql/bin' &gt;&gt; ~/.bash_profile</pre>
</li>
<li>If no /private/etc/php.ini exists, make a copy of php.ini.default</li>
<li>Update php.ini to point at the new MySQL socket <em>mysql.default_socket = /private/tmp/mysql.sock</em> &#8211; do this for both mysql and mysqli.
<pre>mysql.default_socket = /private/tmp/mysql.sock
mysqli.default_socket = /private/tmp/mysql.sock</pre>
</li>
</ul>
<p><strong>Other tips if you having problems with .htaccess</strong></p>
<p>Ensure the following directives are enabled (e.g. look in /etc/apache2/users/username.conf) :</p>
<p><code> Options FollowSymLinks<br />
AllowOverride All<br />
</code></p>
]]></content:encoded>
			<wfw:commentRss>http://www.pyrosoft.co.uk/blog/2008/09/16/getting-apache-php-and-mysql-to-work-on-leopard/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Hosting multiple blogs on a single WordPress installation</title>
		<link>http://www.pyrosoft.co.uk/blog/2008/08/31/hosting-multiple-blogs-on-a-single-wordpress-installation/</link>
		<comments>http://www.pyrosoft.co.uk/blog/2008/08/31/hosting-multiple-blogs-on-a-single-wordpress-installation/#comments</comments>
		<pubDate>Sun, 31 Aug 2008 14:16:10 +0000</pubDate>
		<dc:creator>Paul Maunders</dc:creator>
				<category><![CDATA[blogging]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://www.pyrosoft.co.uk/blog/?p=384</guid>
		<description><![CDATA[As you can probably tell from this blog, WordPress is my favourite blogging tool. I&#8217;ve been using it for a couple of years now, and during that time I&#8217;ve been really impressed by it. So when I was recently asked if a single copy of WordPress could be used to power several blogs, I was [...]]]></description>
			<content:encoded><![CDATA[<p>As you can probably tell from this blog, WordPress is my favourite blogging tool. I&#8217;ve been using it for a couple of years now, and during that time I&#8217;ve been really impressed by it. So when I was recently asked if a single copy of WordPress could be used to power several blogs, I was optimistic that it would be up to the job.</p>
<p>And it didn&#8217;t disappoint me&#8230;</p>
<p>There are a number of ways you can host multiple blogs with WordPress:</p>
<ul>
<li><a href="http://mu.wordpress.org/">WordPress MU (multi-user)</a> &#8211; This is system that powers all blogs at wordpress.com, Le Monde, Harvard Univeristy etc&#8230;</li>
<li>Batch management of blogs with <a href="http://birdhouse.org/software/2008/04/wp-create/">WP-Create</a> and WP-Upgrade &#8211; These scripts let you install multiple blogs in parallel, however each one would get it&#8217;s own installation.</li>
<li>Modifying wp-config.php to choose a different database per hostname. This uses the standard wordpress scripts.</li>
</ul>
<p>Since I wanted to use a standard wordpress installation, and I didn&#8217;t want to install it multiple times, I chose the 3rd option. WordPress stores most of it&#8217;s configuration in it&#8217;s database, so all you need to do is modify wp-config.php to point at a different database depending on the hostname of the site being accessed:</p>
<pre>
// Ignore the www. part of a hostname
$host = eregi_replace('^www\.', '', $_SERVER['HTTP_HOST']);

switch ($host) {
        case 'site1.co.uk';
                $db = 'site1';
                break;
        case 'site2.co.uk';
                $db = 'site2';
                break;
        default:
                header("HTTP/1.0 404 Not Found");
                exit();
                break;
}

// ** MySQL settings ** //
define('DB_NAME', $db);    // The name of the database
define('DB_USER', 'user');
define('DB_PASSWORD', 'password');
define('DB_HOST', 'hostname');
</pre>
<p>Simply add the existing database settings code with the code above, and then create a new empty database for each blog you want to host. You will need to run the <em>install</em> scripts for each blog, e.g.  http://www.site1.co.uk/blog/wp-admin/install.php</p>
<p><strong>References:</strong></p>
<ul>
<li>Enterprise 2.0 anyone? &#8211; <a href="http://www.bos89.nl/1216">How to: multiple blogs, one WordPress installation</a></li>
<li>WordPress Codex &#8211; <a href="http://codex.wordpress.org/Installing_Multiple_Blogs">Installing Multiple Blogs</a>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.pyrosoft.co.uk/blog/2008/08/31/hosting-multiple-blogs-on-a-single-wordpress-installation/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>How to remove duplicate data with MySQL</title>
		<link>http://www.pyrosoft.co.uk/blog/2007/05/29/how-to-remove-duplicate-data-with-mysql/</link>
		<comments>http://www.pyrosoft.co.uk/blog/2007/05/29/how-to-remove-duplicate-data-with-mysql/#comments</comments>
		<pubDate>Tue, 29 May 2007 22:30:00 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[mysql]]></category>

		<guid isPermaLink="false">http://www.pyrosoft.co.uk/blog/?p=167</guid>
		<description><![CDATA[Quite often I have found myself wanting to remove some duplicate data from a MySQL table without having to 1) write a script to de-dupe the table or 2) copy the data into a new table with unique indexes. Well fortunately there is a quick (and dirty?) solution. Say for example you wanted to get [...]]]></description>
			<content:encoded><![CDATA[<p>Quite often I have found myself wanting to remove some duplicate data from a MySQL table without having to 1) write a script to de-dupe the table or 2) copy the data into a new table with unique indexes.</p>
<p>Well fortunately there is a quick (and dirty?) solution. Say for example you wanted to get rid of duplicate e-mail addresses in a table, then you could do the following:</p>
<pre>
 ALTER IGNORE TABLE customer ADD UNIQUE (email);
</pre>
<p>By using the IGNORE keyword, it changes the way ALTER TABLE works so that only the first row with a particular e-mail address is kept, further rows containing that e-mail address are simply dropped.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.pyrosoft.co.uk/blog/2007/05/29/how-to-remove-duplicate-data-with-mysql/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
