I set up a simple D6 site with a handful of contrib modules and drush to keep things updated. I ssh'd onto the server a couple days ago because I got an email about upgrades being available and tried to "drush status", but got an html page printed to Terminal about how my site was in offline mode. This was odd, because the site was perfectly accessible in my browser.

So I upgraded to the latest green release of drush (4.0-rc5) and tried again. This time I got status working:

[~/public_html]# drush status
Drupal version : 6.19
Site URI : http://default
Database driver : mysql
Database hostname : localhost
Database username : [db_user]
Database name : [db_name]
Default theme : garland
Administration theme : garland
PHP configuration : /usr/local/lib/php.ini
Drush version : 4.0-rc5
Drush configuration :
Drush alias files :
Drupal root : /home/[user]/public_html
Site path : sites/default

I knew that there were updates available, so I tried to run "drush up", but got this:

[~/public_html]# drush up
Command pm-update needs a higher bootstrap level to run - you will need invoke drush from a more functional Drupal environment to run this command.                                            [error]
Command pm-update needs the following modules installed/enabled to run: update.                                                                                                                [error]
The drush command 'up' could not be executed.                                                                                                                                                  [error]
Drush was not able to start (bootstrap) the Drupal database.                                                                                                                                   [error]
Hint: This error often occurs when Drush is trying to bootstrap a site that has not been installed or does not have a configured database.

You can select another site with a working database setup by specifying the URI to use with the --uri parameter on the command line or $options['uri'] in your drushrc.php file.

My site is working fine in the browser (it's not offline, it's full functional, etc) and the "update status" module is enabled, so I don't know what else this wants. Running this command from inside the "[drupal]/sites/default" folder results in the same error.

I can do simple drush commands that don't require bootstrapping (such as "dl"), but anything requiring the database results in this error (for example, "en"). From #1010238: Clarify when to use site-upgrade, I gathered that I apparently need to run drush with more permissions, but I can't. These sites are on a simple shared hosting account where I don't have enough privileges to chown, chgrp, sudo, or su.

So: What do I need to do to get drush functional?

Comments

greg.1.anderson’s picture

Category: bug » support
Status: Active » Postponed (maintainer needs more info)

Can you use "mysql yourdrupaldatabasename"? Those are the permissions you need to grant yourself -- not filesystem privs. If you cannot read and write the database from the shell, than you can't use drush.

davedelong’s picture

By straight up doing "mysql [dbname]" I cannot access the database. However, if I do "mysql [dbname] -u [dbuser] -p" and then enter the password, I can access the database just fine. In other words, the name of the user on the system is different than the name of the user used to access the database. The former is "user", and the latter is "user_drupal".

greg.1.anderson’s picture

Don't you have "user_drupal" and the db password set up in your site's settings.php file?

Run your drush commands that are failing with -d -s, and see what commands drush is trying to run.

davedelong’s picture

Yes, the username and password are specified in the default/settings.php file as part of the "$db_url" variable.

Output of "drush up -d -s":

[~/public_html]# drush -d -s up
Bootstrap to phase 0. [0.01 sec, 2.34 MB]                            [bootstrap]
Drush bootstrap phase : _drush_bootstrap_drush() [0.02 sec, 2.54 MB] [bootstrap]
Bootstrap to phase 6. [0.03 sec, 5.05 MB]                                                                                                                                                      [bootstrap]
Drush bootstrap phase : _drush_bootstrap_drupal_root() [0.03 sec, 5.05 MB]                                                                                                                     [bootstrap]
Initialized Drupal 6.19 root directory at /home/[user]/public_html [0.04 sec, 5.84 MB]                                                                                                           [notice]
Drush bootstrap phase : _drush_bootstrap_drupal_site() [0.04 sec, 5.85 MB]                                                                                                                     [bootstrap]
Initialized Drupal site default at sites/default [0.04 sec, 5.85 MB]                                                                                                                              [notice]
Drush bootstrap phase : _drush_bootstrap_drupal_configuration() [0.05 sec, 5.85 MB]                                                                                                            [bootstrap]
Can't connect to local MySQL server through socket '/var/tmp/mysql.sock' (2) [0.05 sec, 5.89 MB]                                                                                               [bootstrap]
Bootstrap to phase 5. [0.05 sec, 5.89 MB]                                                                                                                                                      [bootstrap]
Bootstrap to phase 6. [0.05 sec, 5.89 MB]                                                                                                                                                      [bootstrap]
Command pm-update needs a higher bootstrap level to run - you will need invoke drush from a more functional Drupal environment to run this command. [0.05 sec, 5.89 MB]                        [error]
Command pm-update needs the following modules installed/enabled to run: update. [0.05 sec, 5.89 MB]                                                                                            [error]
The drush command 'up' could not be executed. [0.05 sec, 5.89 MB]                                                                                                                              [error]
Drush was not able to start (bootstrap) the Drupal database.                                                                                                                                   [error]
Hint: This error often occurs when Drush is trying to bootstrap a site that has not been installed or does not have a configured database.

I notice there the "Can't connect to local MySQL server through socket '/var/tmp/mysql.sock' (2)" error. "ls -al /var" does not reveal a "tmp" folder. "ls -l" of "/tmp" shows (among a whole lot of other stuff):

lrwxrwxrwx 1 root root 30 Jan 1 00:00 mysql.sock -> ../../var/lib/mysql/mysql.sock

So drush isn't finding the mysql socket?
(specifically, it is line 1160 of environment.inc that is failing)

davedelong’s picture

More info...

admin/reports/status/php shows that:

- "MYSQL_SOCKET" => "/var/tmp/mysql.sock"
- "mysql.default_socket" => "/var/tmp/mysql.sock" (for both local and master value)

My php.ini file has:

; Default socket name for local MySQL connects.  If empty, uses the built-in
; MySQL defaults.
mysql.default_socket =

So php thinks the mysql socket is at /var/tmp/mysql.sock, which apparently works for the production site, but fails for drush?

jonhattan’s picture

It seems the socket is not in the same place for the cli and the web server environment.

I think of two options to workaround this:

1/ Try setting the socket for php-cli by adding `mysql.default_socket = /tmp/mysql.sock` to a drush.ini file. See drush topic docs-ini-files for reference.

or 2/ Try changing 'localhost' by '127.0.0.1' in $db_url. This way mysql should connect via tcp/ip and not by the socket.

davedelong’s picture

I created a drush.ini file at ~/.drush/drush.ini (by copying the example.drush.ini file) and added the mysql.default_socket bit. Re-running "drush up" showed no change in the output.

Also, for what it's worth, "php --info" shows:

MYSQL_SOCKET => /var/tmp/mysql.sock
mysql.default_socket => /var/tmp/mysql.sock => /var/tmp/mysql.sock

So it looks like php-cli is using the same socket as php.

Changing the $db_url to use 127.0.0.1 worked, but isn't connecting over TCP/IP slower than via a socket? If it's not, then I suppose this is an acceptable solution. Otherwise I'd like to stick with the socket file and figure out why drush doesn't want to connect via the socket.

Also, I tried going into the "drush_valid_db_credentials()" functions in environment.inc and changing $creds['port'] to be "/tmp/mysql.sock" (which should have forced mysql to use that socket for connecting instead of the default socket, according to the mysql_connect() documentation...), but this also did not work (and yes, I verified that $creds['driver'] is 'mysql').

jonhattan’s picture

to double check: this doesn't work ?

$link = mysql_connect(':/tmp/mysql.sock', 'mysql_user', 'mysql_password');
$link = mysql_connect('localhost:/tmp/mysql.sock', 'mysql_user', 'mysql_password');

(see example#3 in http://es2.php.net/mysql_connect)

about performance: http://forums.devshed.com/php-development-5/php-mysql-performance-socket...

davedelong’s picture

@jonhattan correct. Manually changing the $hostspec variable at environment.inc:1159 to either 'localhost:/tmp/mysql.sock' or ':/tmp/mysql.sock' results in a bunch of html outputted to the console. It's the "site offline" html page, and after the </html> tag is:

Drush command terminated abnormally due to an unrecoverable error.                                                                                                                    [error]
Error: Directive 'magic_quotes_gpc' is deprecated in PHP 5.3 and greater in Unknown, line 0

I tried adding the following to my .htaccess file, but I'm not sure what difference that would make to drush...

php_flag magic_quotes_gpc Off
php_value magic_quotes_gpc Off
rowbotony’s picture

Version: 6.x-4.0-rc5 » 7.x-4.4
Component: Core Commands » SQL
Category: support » bug
Priority: Critical » Minor
Status: Postponed (maintainer needs more info) » Needs review

Hi, I've been banging my head against the wall for the past 2 hours on a problem similar to this on my Drupal 7 multisite install. Finally this issue post helped me track down and solve my problem. I'll try to keep this brief... the problem I had was that "Drush was not able to start (bootstrap) the Drupal database". This problem was caused by my mysql.sock being in a non-standard location. The solution, for me, was to set mysql.sock to /tmp/mysql.sock.

I'm using a Bitnami LAMP stack on an AWS EC2 instance. Bitnami installs Apache and MySQL in the /opt/bitnami directory. So the MySQL socket on this stack is running at /opt/bitnami/mysql/tmp/mysql.sock. I already had problems with this when installing the site initially, I had to set my D7 setting.php to use 'unix_socket' => '/opt/bitnami/mysql/tmp/mysql.sock',, fine, no big deal, production site works fine.

I eventually discovered tonight that this was the problem for Drush not working too. My D6 site on the same server works just fine with all Drush commands remotely and locally, but the mysql.sock being in this non-standard bitnami directory caused Drush to fail on my D7 multisite with the error Drush was not able to start (bootstrap) the Drupal database. I changed the socket path in every config file; my.cnf, php.ini, drush.ini, yet still this didn't solve the problem. I found ultimately that the bitnami control script /opt/bitnami/mysql/scripts/ctl.sh sets the socket via a command line argument, so it didn't matter how many config files I changed, I had to change the path in this ctl.sh script.

Long story short, I know you are not running a bitnami stack, but your problem seems similar to mine, which was due to the mysql.sock being in a non-standard location. To test and troubleshoot the theory I simply did an ln -s /opt/bitnami/mysql/tmp/mysql.sock /tmp/, tada! That fixed drush, now drush works locally and remotely, then I spent the next hour tracking down that dang ctl.sh script.

My only feedback would be - why didn't drush pickup my socket from sites/mysite1/settings.php? drush.ini still failed for me even after adding mysql.default_socket = /opt/bitnami/mysql/tmp/mysql.sock. The multisite settings.php had in the array 'unix_socket' => '/opt/bitnami/mysql/tmp/mysql.sock',, why didn't drush pick that up? Was there a command line option I could have used to have drush recognize that? How would I have added this socket location to a drush aliases.drushrc.php file? I did see for D7 there is a "databases" option, but I have found no documentation about the syntax of how to use databases, is it the same syntax as the db-url option for D6? I hope this helps someone, thank you.

-Tony

winnall’s picture

I had this problem too. I'm using Drush 7.x-4.4 with Drupal 6.20 and PostgreSQL.

It seems that Drush could not find the PostgreSQL driver, which is normally set up in php.ini. So I created a directory /etc/drush and put a soft link inside it pointing to my php.ini (which already had the PostgreSQL driver enabled).

Drush then worked.

Steve

moshe weitzman’s picture

Status: Needs review » Postponed (maintainer needs more info)

never heard of unix_socket in settings.php. Is that documented somewhere? It seems like D7 does not support sockets: #537880: Installation using socket rather than host

rowbotony’s picture

Even looking through my browsing history I have no idea where I found the reference to 'unix_socket' in settings.php... but it worked and it is supported. I could only find a reference to it in the database.inc file here: http://api.drupal.org/api/drupal/includes--database--mysql--database.inc...

// The DSN should use either a socket or a host/port.
    if (isset($connection_options['unix_socket'])) {
      $dsn = 'mysql:unix_socket=' . $connection_options['unix_socket'];
    }

I'm done with Bitnami anyhow, I moved all of my sites to a standard Ubuntu 10.04 LAMP stack :)

moshe weitzman’s picture

Title: Drush can't bootstrap » Support unix_socket in D7 $databases var in settings.php
Version: 7.x-4.4 »
Category: bug » feature
Priority: Minor » Normal
Status: Postponed (maintainer needs more info) » Active
mattez’s picture

Comment #6 try 2) worked form me. I changed DB setup in settings.php from 'localhost' to its IP '127.0.0.1'

diegohermes’s picture

subscribe

moshe weitzman’s picture

I'd welcome a patch for drush so that we can support socket like drupal 7 does (see #13)

Kjartan’s picture

Status: Active » Closed (duplicate)