9

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?

  • Have you read this discussion? – nicael Jul 12 '14 at 5:34
  • 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 Jul 12 '14 at 5:38
  • 5
    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 Jul 12 '14 at 7:23
  • 1
    @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 Jul 12 '14 at 16:32
  • @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 Jul 13 '14 at 21:27
3

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!

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.