Installation Error "1046 No database selected" Summary

I'm getting the following error when attempting to install a new Craft site locally:

CDbCommand failed to execute the SQL statement: SQLSTATE[3D000]: Invalid catalog name: 1046 No database selected. The SQL statement executed was: SHOW TABLES LIKE 'craft_%'


Having just downloaded the ZIP, I assume the version of Craft in question is the latest at time of writing (2.1.2563).

Point of failure

After some digging, the error appears to be caused by line 59 in craft/app/etc/behaviors/AppBehavior.php, specifically the call to craft()-&gt;db-&gt;tableExists():

$this-&gt;_isInstalled = (craft()-&gt;isConsole() || craft()-&gt;db-&gt;tableExists('info', false));


If that is indeed the case, it means that the preceding craft()-&gt;getComponent('db') and craft()-&gt;getIsDbConnectionValid() checks are passing, which leaves me completely baffled as to what is causing the error.

Environment info

The site is (not) running on a local Vagrant VM, which is happily hosting another Craft site with no problems. It's perhaps worth noting that I didn't install the other site from scratch on this server.

The basic server specs are as follows:


Ubuntu 12.04 LTS (64-bit)
Apache 2.2.22
PHP 5.4.30


The database definitely exists, and I can connect to it using Sequel Pro.

Has anybody else run into this?
While it may be an unsatisfying answer, for the sake of completion, this question was resolved by completely destroying and rebuilding the exact same VM.

Short discussion on Twitter about it here:

https://twitter.com/monooso/status/487831027327696896

I have a warm affection for the on/off technique.  I've even seen it fix elevators!