<?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>theChrisWalker.net &#187; MySQL</title>
	<atom:link href="http://thechriswalker.net/tag/mysql/feed" rel="self" type="application/rss+xml" />
	<link>http://thechriswalker.net</link>
	<description>I like Web Development</description>
	<lastBuildDate>Tue, 31 Aug 2010 07:42:25 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>VPS Migration for thechriswalker.net &#8211; New Host, New OS, no Plesk</title>
		<link>http://thechriswalker.net/2010-03/vps-migration-for-thechriswalker-net-new-host-new-os-no-plesk.html</link>
		<comments>http://thechriswalker.net/2010-03/vps-migration-for-thechriswalker-net-new-host-new-os-no-plesk.html#comments</comments>
		<pubDate>Thu, 25 Mar 2010 19:16:21 +0000</pubDate>
		<dc:creator>Chris</dc:creator>
				<category><![CDATA[Not Code]]></category>
		<category><![CDATA[MongoDB]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Server Administration]]></category>

		<guid isPermaLink="false">http://thechriswalker.net/?p=198</guid>
		<description><![CDATA[Not that I didn&#8217;t like Plesk. I just have the urge to understand things well, and I couldn&#8217;t understand all of how Plesk worked&#8230; So I wanted it &#8220;all-manual&#8221;, like the true hardcore (read: idiot) I am. I had been using a VPS to host this website (amongst other things) and it was getting old. [...]]]></description>
			<content:encoded><![CDATA[<p>Not that I didn&#8217;t like Plesk. I just have the urge to understand things well, and I couldn&#8217;t understand all of how Plesk worked&#8230; So I wanted it &#8220;all-manual&#8221;, like the true hardcore (read: <em>idiot</em>) I am.</p>
<p>I had been using a VPS to host this website (amongst other things) and it was getting old. It ran on CentOS 4 and used Plesk as a control panel. PHP was down at version 4.2.2 or something and MySQL still at version 4.x. I didn&#8217;t understand server administration as well as I do now and the whole thing was a bit of a mess. So I decided a fresh start, with a VPS on more powerful hardware and built cleanly.</p>
<p>So I went for a basic VPS from <a href="http://www.34sp.com">34SP.com</a> with no control panel and using Ubuntu 9.04 as the OS. They set up the server quickly and so I went about configuring it how I wanted. There were a couple of snags along the road and so I&#8217;ll tell you about them here too.</p>
<p><span id="more-198"></span></p>
<h2>The Basics, disabling root.</h2>
<p>First things first, the VPS came with the root account enabled and that as the only user on the system. Now I like to have my root account disabled and use sudo, so I created an admin user, granted sudo rights and disabled the root account. The command used are below.</p>
<p>Create user and set password:</p>
<div class="codecolorer-container bash mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #666666; font-style: italic;"># useradd admin</span><br />
<span style="color: #666666; font-style: italic;"># passwd admin</span><br />
<span style="color: #666666; font-style: italic;"># visudo</span></div></div>
<p>Now in the sudoer&#8217;s file you&#8217;ll see a line for root which looks something like:</p>
<div class="codecolorer-container text mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">root ALL=(ALL) ALL</div></div>
<p>duplicate this line but with you&#8217;re username:</p>
<div class="codecolorer-container text mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">admin ALL=(ALL) ALL</div></div>
<p>save and exit. Now log out of <tt>root</tt> and back in as <tt>admin</tt>, then disable the root account:</p>
<div class="codecolorer-container bash mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">$ <span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">passwd</span> <span style="color: #660033;">-l</span> root</div></div>
<p>and we&#8217;re done!. Now on this system my home directory wasn&#8217;t created (probably because I didn&#8217;t give the right flags in the <tt>useradd</tt> command. So we need to make it.</p>
<div class="codecolorer-container bash mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">$ <span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">mkdir</span> <span style="color: #660033;">-p</span> <span style="color: #000000; font-weight: bold;">/</span>home<span style="color: #000000; font-weight: bold;">/</span>admin</div></div>
<h2>LAMP Stack</h2>
<p>34SP had installed Apache but not PHP or MySQL, both of which I wanted. In fact I wanted the following:</p>
<ul>
<li> Apache with mod_rewrite</li>
<li> PHP5.3+ (5.3 is important to me) with APC, Xdebug and MongoDB</li>
<li> MongoDB server </li>
<li> MySQL5 server </li>
</ul>
<p>I also needed to migrate my blog from it&#8217;s current location, to the new server. The Blog uses WordPress 2.8.something and the latest version at time of writing is 2.9.2 (time to upgrade!). WordPress doesn&#8217;t mention PHP5.3 support so this could be fun.</p>
<p>So, first hurdle, the default Ubuntu Repositories do not have packages for PHP5.3. This leaves 2 options, compile from source or find a repositiory which does have the packages. Knowing which I&#8217;d prefer and having already heard of dotdeb.org I added the dotdeb.org PHP5.3 repository to my <tt>sources.list</tt> and then I could install PHP5.3.2 and xdebug and apc right from <tt>apt</tt>!</p>
<p>After editing <tt>/etc/apt/sources.list</tt>:</p>
<div class="codecolorer-container bash mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">$ <span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">apt-get</span> update<br />
$ <span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">apt-get</span> <span style="color: #c20cb9; font-weight: bold;">install</span> php5 php5-mysql php5-cli php5-xdebug php5-apc mysql5-server</div></div>
<p>But I also wanted MongoDB which is only available as a PECL module. So I need the <tt>php5-dev</tt> package. unfortunately, this gave me an error about <tt>libtool</tt> not being the correct version. and the only way to resolve it (that I could find) was to use libtool from the previous Ubuntu release.</p>
<div class="codecolorer-container bash mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">$ <span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">apt-get</span> purge libtool<br />
$ <span style="color: #c20cb9; font-weight: bold;">wget</span> http:<span style="color: #000000; font-weight: bold;">//</span>cn.ubuntu.com<span style="color: #000000; font-weight: bold;">/</span>hardy<span style="color: #000000; font-weight: bold;">/</span>libtool.deb<br />
$ <span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">dpkg</span> <span style="color: #660033;">-i</span> libtool.deb<br />
$ <span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">apt-get</span> <span style="color: #c20cb9; font-weight: bold;">install</span> php5-dev</div></div>
<p>Then it worked like a dream and I could finally use <tt>pecl</tt></p>
<div class="codecolorer-container bash mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">$ <span style="color: #c20cb9; font-weight: bold;">sudo</span> pecl <span style="color: #c20cb9; font-weight: bold;">install</span> mongo</div></div>
<p>That was the PHP module, but what about the actual MongoDB server itself? Well, there&#8217;s a repository for that as well. Add it to your sources.list, update then you can <tt>apt-get install mongodb</tt>. no configuration necessary. The phpinfo() output shows the mongo extension installed correctly and the mongo shell functions to show the mongodb server is working fine.</p>
<p>OK, now time to get my blog up and running, so I create a new virtual host in <tt>/etc/apache2/sites-available</tt> and use the apache tool to enable it <tt>sudo a2ensite thechriswalker.net</tt>. I have all my virtual hosts in <tt>/var/www/vhost/<domain>/{httpdocs,logs}</tt>, I change to the httpdocs directory and grab wordpress <tt> wget http://wordpress.org/latest.tar.gz</tt>, unzip and browse to it to see if it worked!</p>
<p>Well, of course it didn&#8217;t &#8211; I hadn&#8217;t done a couple of things. First I needed to restart Apache to enable the Virtual Host I had created. Then I realised that the DNS hadn&#8217;t propagated so I needed to set a static <tt>hosts</tt> entry on my local computer. This done I tried again &#8211; success!</p>
<p>So I dumped the database from the old VPS, copied (scp&#8217;d) my custom theme, plugins and some other non-wordpress content across to the new one. On the new one, I imported the wordpress database and tried to access it again. It took me through a 2 step &#8220;we need to update your database&#8221; (it was 2.8 not 2.9 remember) screen which worked great! That was easier than expected and I haven&#8217;t seen anything behave oddly under PHP5.3 &#8211; result.</p>
<h2>More</h2>
<p>Now I just need to setup the email side of things, I want to be able to send and recieve mail securely through this server, but thats a job for another day&#8230; Also I moved the email for this domain over to Google Apps, as I like GMail so much, so I may not even bother with the email part of this!</p>
]]></content:encoded>
			<wfw:commentRss>http://thechriswalker.net/2010-03/vps-migration-for-thechriswalker-net-new-host-new-os-no-plesk.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Regular Expressions in MySQL</title>
		<link>http://thechriswalker.net/2009-01/regular-expressions-in-mysql.html</link>
		<comments>http://thechriswalker.net/2009-01/regular-expressions-in-mysql.html#comments</comments>
		<pubDate>Fri, 23 Jan 2009 09:40:16 +0000</pubDate>
		<dc:creator>Chris</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[Regular Expressions]]></category>

		<guid isPermaLink="false">http://thechriswalker.net/?p=21</guid>
		<description><![CDATA[I like regular expressions. Anyone who has tried to understand them will understand the learning curve involved and in no way do I claim to be an expert. However, I use them all the time. They are possibly the most useful thing I have ever learnt to do with programming and are more powerful I [...]]]></description>
			<content:encoded><![CDATA[<p>I like regular expressions. Anyone who has tried to understand them will understand the learning curve involved and in no way do I claim to be an expert. However, I use them all the time. They are possibly the most useful thing I have ever learnt to do with programming and are more powerful I imagined at first.</p>
<h3>So what does this have to do with MySQL?</h3>
<p>Well, I was recently dealing wit a table in which there is some inline JSON serialised data. This makes sense for the situation but of course if you want to query on something within the data you have to be a bit more careful. You have two options as I saw it yesterday:</p>
<ul>
<li>Pull all the data and parse it out outside of the database <em>- which seems weak and inefficient.</em></li>
<li>Use some LIKE query to pull likely candidates and then parse out of the data base <em>- again not so good, but a bit better.</em></li>
</ul>
<p><span id="more-21"></span></p>
<h3>The solution!</h3>
<p>You can use Regular Expressions in a MySQL query! To simplify the problem I faced, suppose you have a field in the database which contains JSON data like this:</p>
<div class="codecolorer-container javascript mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="javascript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #009900;">&#123;</span> <span style="color: #3366CC;">&quot;content&quot;</span><span style="color: #339933;">:</span><span style="color: #009900;">&#91;</span><span style="color: #CC0000;">1</span><span style="color: #339933;">,</span><span style="color: #CC0000;">4</span><span style="color: #339933;">,</span><span style="color: #CC0000;">56</span><span style="color: #339933;">,</span><span style="color: #CC0000;">578</span><span style="color: #339933;">,</span><span style="color: #CC0000;">600</span><span style="color: #339933;">,</span><span style="color: #CC0000;">601</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">&quot;next&quot;</span><span style="color: #339933;">:</span><span style="color: #CC0000;">56</span> <span style="color: #009900;">&#125;</span></div></div>
<p>And I want to find all records which contain a specific value in the &#8220;content&#8221; array (and suppose I know which records will have the &#8220;content&#8221; array by another field/method). LIKE would not be enough as it leaves to much room for error, but Regular Expressions &#8211; easy! If I want to find the value 578 then:</p>
<div class="codecolorer-container mysql mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="mysql codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #990099; font-weight: bold;">SELECT</span> <span style="color: #CC0099;">*</span> <span style="color: #990099; font-weight: bold;">FROM</span> <span style="color: #008000;">`table`</span> <span style="color: #990099; font-weight: bold;">WHERE</span> <span style="color: #008000;">`json<span style="color: #008080; font-weight: bold;">_</span>data`</span> <span style="color: #CC0099; font-weight: bold;">REGEXP</span> <span style="color: #008000;">'<span style="color: #004000; font-weight: bold;">\\</span>[([0-9]*,)*578(,|<span style="color: #004000; font-weight: bold;">\\</span>])'</span><span style="color: #000033;">;</span></div></div>
<p>Would find all records with 578 as an element in an array containing only numbers. Combine this with the method for restricting the SELECT to only filed you know will contain data in the right format and you have done it!</p>
<p>This is but one example, and the technique seems most useful when you have a serialised data format in your database field, but could be useful for advanced searching in table that do not support &#8220;fulltext&#8221; searches.</p>
]]></content:encoded>
			<wfw:commentRss>http://thechriswalker.net/2009-01/regular-expressions-in-mysql.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
