Drush not selecting database I'm using a Vagrant environment generated from https://puphpet.com/ for a Drupal project &amp; it is all going well except for Drush which gives me an error any time I try running "drush cc -all", see the error below.

&lt;h1&gt;Additional uncaught exception thrown while handling exception.&lt;/h1&gt;&lt;h2&gt;Original&lt;/h2&gt;&lt;p&gt;PDOException: SQLSTATE[3D000]: Invalid catalog name: 1046 No database selected: SELECT 1 FROM {blocked_ips} WHERE ip = :ip; Array
(
[:ip] =&amp;amp;gt; 127.0.0.1
)
in drupal_is_denied() (line 1933 of /var/www/includes/bootstrap.inc).&lt;/p&gt;&lt;h2&gt;Additional&lt;/h2&gt;&lt;p&gt;PDOException: SQLSTATE[3D000]: Invalid catalog name: 1046 No database selected: SELECT * FROM {system} WHERE type = &amp;amp;#039;theme&amp;amp;#039; OR (type = &amp;amp;#039;module&amp;amp;#039; AND status = 1) ORDER BY weight ASC, name ASC; Array
(
)
in system_list() (line 165 of /var/www/includes/module.inc).&lt;/p&gt;&lt;hr /&gt;Drush command terminated abnormally due to an unrecoverable error.                                                                                                                       [error]


From what I gather the problem is that it isn't selecting a database. Does anyone know where the details for this would be stored? The Drupal site itself is connecting &amp; using the database fine.

I'm not sure if this would cause and issue but the database details for the Drupal site are stored as an Apache environmental variable.
What you are seeing above is a bug in Drush where Drush cannot bootstrap the database of a Drupal site if the database credentials are correct, but the database itself is empty.  To fix this problem:


If your database is empty, run "drush site-install" to create a database.
If your database is not empty, check the settings of your database prefix, and make sure that it is correct.


This was recently fixed in https://github.com/drush-ops/drush/pull/1442.