<p>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.</p>

<p>Short discussion on Twitter about it here:</p>

<p><a href="https://twitter.com/monooso/status/487831027327696896" rel="nofollow">https://twitter.com/monooso/status/487831027327696896</a></p>

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

CC BY-SA 3.0
2014-07-13T21:22:34.100Z
What Ben said...
Stephen Lewis
CC BY-SA 3.0
2014-07-12T23:51:56.173Z
2014-07-12T23:51:56.173Z
Ben Parizek
<p>I have seen a few random errors when using Craft and Vagrant that made me feel nutty after troubleshooting. I came to the same conclusion that you did, destroying the machine and rebuilding seemed to solve the issue but didn't quite give me the answer I felt I was owed.</p>

<p>So I did some digging...</p>

<p>I found the culprit to be the sync functionality of Vagrant. Back when Vagrant first came onto the scene one of the major issues was syncing folders with a lot of files and directories, aka a CMS. I can't find the direct link but I believe some people had issues with virtual box guest addition tools.</p>

<p>I'm not saying that your vagrant machine is really old, that tends not to be the case. However, I am saying that sometimes - not sure when and why - the sync function can corrupt or even not sync directories/files.</p>

<p>If you run into this again, I would make sure you diff the files in question on the host and guest machine. Especially looking for invisible characters.</p>

<p>Also worthy to note, but I have zero experience with this. Vagrant allows you to use VMWare as the provider which claims improved performance. One downside is that it costs $79 for a license - but it also goes towards funding future development of Vagrant. Details on the VMWare provider are here: </p>

<p><a href="https://www.vagrantup.com/vmware" rel="nofollow">https://www.vagrantup.com/vmware</a></p>

CC BY-SA 3.0
2014-07-13T12:39:30.060Z
2014-07-13T12:39:30.060Z
Jason McCallister
<h2>Summary</h2>

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

<pre><code>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_%'
</code></pre>

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

<h2>Point of failure</h2>

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

<pre><code>$this-&gt;_isInstalled = (craft()-&gt;isConsole() || craft()-&gt;db-&gt;tableExists('info', false));
</code></pre>

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

<h2>Environment info</h2>

<p>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.</p>

<p>The basic server specs are as follows:</p>

<ul>
<li>Ubuntu 12.04 LTS (64-bit)</li>
<li>Apache 2.2.22</li>
<li>PHP 5.4.30</li>
</ul>

<p>The database definitely exists, and I can connect to it using Sequel Pro.</p>

<p>Has anybody else run into this?</p>

CC BY-SA 3.0
2014-07-12T05:34:48.330Z
Have you read [this](http://meta.craftcms.stackexchange.com/questions/29/how-do-i-submit-a-bug-issue-with-craft) discussion?
nicael
CC BY-SA 3.0
2014-07-12T05:38:52.120Z
I did. The G+ site explicitly recommends using SE when seeking help, and I can't submit a bug report via the CP, as there is no CP (yet). Also, I'm not suggesting this is a bug in Craft (if it was, others would doubtless have encountered it by now, and P&T would probably have fixed it in minutes), so SE seemed like the most appropriate forum for discussion.
Stephen Lewis
CC BY-SA 3.0
2014-07-12T07:23:08.973Z
This isn't so much an answer, as a mea culpa. After completely destroying the VM, and starting from scratch (with the exact same provisioning), the problem resolved itself.

I'm still baffled as to why this happened, particularly as nothing has changed in terms of the VM configuration, but will happily accept this mysterious solution for now.

If I ever figure out the root cause of the problem, I'll post an actual answer.
Stephen Lewis
CC BY-SA 3.0
2014-07-12T16:32:09.110Z
@StephenLewis I'd go ahead and post that as an answer anyway, on the off chance it resolves the situation for someone else.  If you ever find a "proper" solution, you can always edit it.
Brad Bell
CC BY-SA 3.0
2014-07-13T21:27:34.080Z
@BradBell I tried originally, but SE insisted I wait for a further 8 hours, and then that pesky Ben Parizek stole my thunder. I've accepted his answer.
Stephen Lewis
CC BY-SA 3.0
2014-07-13T21:47:02.043Z
Figures... the only thing more annoying than SE is @BenParizek.
Brad Bell
<database><server><install><error-message>
Installation Error "1046 No database selected"
# Installation Error "1046 No database selected"

(Asked by: username_0 on 2014-07-12)

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()->db->tableExists():
$this->_isInstalled = (craft()->isConsole() || craft()->db->tableExists('info', false));

If that is indeed the case, it means that the preceding craft()->getComponent('db') and craft()->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?

**Tags:** database, server, install, error-message
> **Comments:**
> **username_1**: Have you read [this](http://meta.craftcms.stackexchange.com/questions/29/how-do-i-submit-a-bug-issue-with-craft) discussion?  
> **username_0**: I did. The G+ site explicitly recommends using SE when seeking help, and I can't submit a bug report via the CP, as there is no CP (yet). Also, I'm not suggesting this is a bug in Craft (if it was, others would doubtless have encountered it by now, and P&T would probably have fixed it in minutes), so SE seemed like the most appropriate forum for discussion.  
> **username_0**: This isn't so much an answer, as a mea culpa. After completely destroying the VM, and starting from scratch (with the exact same provisioning), the problem resolved itself.  I'm still baffled as to why this happened, particularly as nothing has changed in terms of the VM configuration, but will happily accept this mysterious solution for now.  If I ever figure out the root cause of the problem, I'll post an actual answer.  
> **username_2**: @StephenLewis I'd go ahead and post that as an answer anyway, on the off chance it resolves the situation for someone else.  If you ever find a "proper" solution, you can always edit it.  
> **username_0**: @BradBell I tried originally, but SE insisted I wait for a further 8 hours, and then that pesky Ben Parizek stole my thunder. I've accepted his answer.  
> **username_2**: Figures... the only thing more annoying than SE is @BenParizek.  

---

## 2 answers

### Answer by username_3 on 2014-07-12. Score: 3 | Accepted answer

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!

> **Comments:**
> **username_0**: What Ben said...  

---

### Answer by username_4 on 2014-07-13. Score: 3

I have seen a few random errors when using Craft and Vagrant that made me feel nutty after troubleshooting. I came to the same conclusion that you did, destroying the machine and rebuilding seemed to solve the issue but didn't quite give me the answer I felt I was owed.

So I did some digging...

I found the culprit to be the sync functionality of Vagrant. Back when Vagrant first came onto the scene one of the major issues was syncing folders with a lot of files and directories, aka a CMS. I can't find the direct link but I believe some people had issues with virtual box guest addition tools.

I'm not saying that your vagrant machine is really old, that tends not to be the case. However, I am saying that sometimes - not sure when and why - the sync function can corrupt or even not sync directories/files.

If you run into this again, I would make sure you diff the files in question on the host and guest machine. Especially looking for invisible characters.

Also worthy to note, but I have zero experience with this. Vagrant allows you to use VMWare as the provider which claims improved performance. One downside is that it costs $79 for a license - but it also goes towards funding future development of Vagrant. Details on the VMWare provider are here:

<https://www.vagrantup.com/vmware>


---

