I was getting the following error message after executing the drush command, drush statusmodules. (Hopefully it will work (fix) in the same way with other drush command as well.)

Full text of the error message I received is as follows:

Command statusmodules needs a higher bootstrap level to run - you will need invoke drush from a more functional Drupal environment to run this command.

The command 'drush.php sm' could not be executed.

I used the following post as reference:

http://www.hazelconsulting.com/blog/troubleshooting-drush-bootstrap-loca...

So, I modified the settings.php file, and changed the following line.

From:

$db_url = 'mysqli://moses:mosespass@localhost/groups

To:

$db_url = 'mysqli://moses:mosespass@127.0.0.1/groups

And the problem went away.

Seems like a drush issue that needs to be fixed, and localhost should be an accepted alias for the IP address 127.0.0.1.

Comments

greg.1.anderson’s picture

Category: bug » support

Interesting; I use 'localhost' in my $db_url, and it works just fine (using drush-HEAD from today). Check the network settings on your machine (e.g. make sure you have 127.0.0.1 localhost in your /etc/hosts file if you are on Linux) -- although I presume your db settings work from Drupal?

Also, please note that Drush 2.1 is no longer actively maintained. You could try drush-3.0-alpha-1 and see if that works better for you. We are working towards a stable release of drush 3; sorry for any inconvenience.

owen barton’s picture

I think we have seen this issue before.

This is probably occurring because php is trying to connect to mysql via a socket and does not have permission to (or the socket is broken), replacing localhost with 127.0.0.1 forces it to use an IP connection, and hence it succeeds. Why it would work from the web, but not cli is probably either because the php web user has permissions to access the socket, or because the web php.ini a difference causing it to use IP connections.

greg.1.anderson’s picture

Status: Active » Closed (works as designed)

Hm, yes, that makes sense. I'm using postgres, so I wouldn't see mysql issues in any event.

Anyway, this doesn't look like a drush issue, so I'll close it.

momo18’s picture

Regarding my original post, perhaps someone can explain what I was doing wrong?

For reference, I used a fresh installation of ubuntu. I executed the drush command with sudo. So I had all permissions. One or two other drush commands that were executed in the same fashion executed OK.

I used all standard methods to setup my test environment on localhost. Created a MySql user to configure database and provided all permissions to database, etc. This is not a show-stopper.

But perhaps someone can explain what I might have setup wrong?

Thanks.

Mac Clemmens’s picture

I'm experiencing the same problem. 127.0.0.1 works OK, but localhost does not.

hixster’s picture

Component: Code » PM (dl, en, up ...)

I'm trying to use drush generate-makefile myfile.make which fails due to the database connection issue mentioned here.
I found this post via Google whilst looking for an answer.

We use MAMP for our local development and i've tried replacing localhost in my settings file with 127.0.0.1 but this breaks the site and doesn't solve the drush issue.
127.0.0.1 is the address I have set in my /etc/hosts file.

Can anyone suggest a solution?

**Update**

On closer inspection of the drush output , it seems to find the database, but the baseurl is wrong.

Drush was attempting to connect to : 
  Drupal version    : 6.16
  Site URI          : http://default
  Database driver   : mysqli
  Database hostname : localhost
  Database username : hixster
  Database name     : xxxxxxxxxxxx
  Default theme     : garland
  Administration theme: garland
  PHP configuration : /Applications/acquia-drupal/php/bin/php.ini
  Drush version     : 4.4
  Drush configuration: 
  Drush alias files : 
  Drupal root       : /Applications/MAMP/htdocs/xxxxxxxxxxxxx
  Site path         : sites/default
  Modules path      : sites/all/modules
  Themes path       : sites/all/themes
  %paths            : Array
joestewart’s picture

hixster: It appears your command line php isn't the MAMP one that can connect to the mysql server ( php -i | grep -i mysql and or php --version) . There are a few ways around this. Here is an old post that explains it - http://raincitystudios.com/blogs-and-pods/steve-krueger/how-use-drush-lo...

Update: Oh, and this is an old closed issue. Better to create a new one and reference other pertinent issues.

hixster’s picture

HI Joe, will open another issue then - I tried linking to the MAMP PHP in the suggested article, but still experience the same issue.
I know the tutorial is old,as it goes on to mention linking to drush.php which I don't have - I do have drush added to my path so i'm not sure that step is necessary?

dhalbert’s picture

Even though this issue is closed, I would like to add a cautionary note, since it shows up close to the top in websearch results. I want to caution you a bit about changing "localhost" to "127.0.0.1" in your settings.php to get drush to run, and explain in more detail what is going on:

  1. When the MySQL client library sees "localhost" as the host name, it special-cases its behavior to use a local socket to connect to the MySQL server, instead of looking up the hostname "localhost" in DNS and making a networked TCP/IP connection. This is in the interest of efficiency. This has been argued to be weird non-standard behavior by MySQL and a bug, but it is documented to do this and it is not going to change anytime soon.
  2. In typical Linux shared hosting, "localhost" works when PHP runs for a web page because PHP is running in a privileged environment where it can see the socket path, typically /var/lib/mysql/mysql.sock.
  3. However, when you run drush from the command line, you are typically running in jailshell, which restricts access to many places. You probably cannot access /var/lib/mysql/mysql.sock, and neither can drush:
    $ drush cc
    Command cache-clear needs a higher bootstrap level to run
    ...
    

    Use drush -d to see what is going on:

    $ drush -d cc
    ...
    SQLSTATE[HY000] [2002] Can't connect to local MySQL server through   [bootstrap]
    socket '/var/lib/mysql/mysql.sock' (2) [0.09 sec, 6.51 MB]
    ...
    

    In fact, any attempt to use mysql with localhost will fail, not just via drush. For instance:

    $ mysql                    # assumes localhost
    ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)
    $ mysql -h localhost
    ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)
    $ mysql -h 127.0.0.1    # This will work
    
  4. So yes, it will work to change settings.php to 127.0.0.1 to make drush work, but then Drupal will always use a TCP/IP connection instead of a local socket, which could be slower. Whether it is really any slower in practice I don't know, and probably depends on your webhost.
  5. A better solution would be to be able to specify a different settings.php for use by drush, or be able to override the database connection settings. There are several drush issues floating around that seem to have patches to do something like that, and maybe it is even part of drush 5. I am a drush novice and am not sure.

bassplaya’s picture

I had the same issue and the change in the settings file to 127.0.0.1 did work for me as well but I have to say that my configuration was different. I had the following lines in my hosts file which I later commented out when I was using the 127.0.0.1 in my settings.php file:

127.0.0.1 www.sandboxd7
127.0.0.1 www.sandboxd6

and in my httpd.conf file living under /Applications/MAMP/conf/apache/httpd.conf I had:

NameVirtualHost www.sandboxd7

DocumentRoot "/Users/GraphicDesign/Sites/www.sandboxd7"
ServerName www.sandboxd7

NameVirtualHost www.sandboxd6

DocumentRoot "/Users/GraphicDesign/Sites/www.sandboxd6"
ServerName www.sandboxd6

I had done this to use multiple sites which are clearly living under: /Users/GraphicDesign/Sites/ so I could simply target the following url in my browser to work on one of my sites without changing the preferences in the MAMP preference pane all the time: http://www.sandboxd6 or http://www.sandboxd7

If anyone knows a way how I can still use my previous configuration for working on many sites at once using drush that would be just awesome.