I am using two MYSQL sockets, the built-in one and the one provided by MAMP. Drush however looks only for the default way and I did not find a way to customize the socket location in drushrc.php. I know you can symlink but that is not a very flexible solution (as reported here: #251837: E: Could not locate the Drupal installation directory. Aborting.). Thanks for any feedback on this.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

moshe weitzman’s picture

Status: Active » Postponed (maintainer needs more info)

How does regular drupal let you use specify socket file?

z.stolar’s picture

#251837: E: Could not locate the Drupal installation directory. Aborting. worked just fine for me. Why isn't it flexible?
However, it's strange, since my local Drupal installations work just fine with no specific config. Is it related to apache in any way?

PGNetDev’s picture

i'd stepped away from drupal for a bit; upgrade drupal & drush this morning. noticed that drush was trying to read the wrong socket as above.

drupal picks up socket info from the mysqli.ini file, as it should:

rpm -qa | grep -i mysql
mysql-client-5.1.36-68.1.i586
libmysqlclient_r16-5.1.36-68.1.i586
php5-mysql-5.3.1-29.1.i586
libmysqlclient16-5.1.36-68.1.i586
apache2-mod_auth_mysql-3.0.0-4.1.i586
mysql-5.1.36-68.1.i586
libmysqlclient-devel-5.1.36-68.1.i586

grep sock /etc/php5/conf.d/*sql*
/etc/php5/conf.d/mysqli.ini:mysqli.default_socket = /var/cache/mysql/mysql.sock
/etc/php5/conf.d/mysql.ini:mysql.default_socket = /var/cache/mysql/mysql.sock

php -i | grep -i sock
...
Configure Command => '../configure' '--prefix=/usr' ... '--with-mysql-sock=/var/run/mysql/mysql.sock' '--with-mysqli=shared' ... '--with-pdo-mysql=shared,/usr' ...
...
MYSQL_SOCKET => /var/run/mysql/mysql.sock
mysql.default_socket => /var/cache/mysql/mysql.sock => /var/cache/mysql/mysql.sock
MYSQLI_SOCKET => /var/run/mysql/mysql.sock
mysqli.default_socket => /var/cache/mysql/mysql.sock => /var/cache/mysql/mysql.sock

drush updatedb
SQLSTATE[HY000] [2002] Can't connect to local MySQL server through socket '/var/run/mysql/mysql.sock' (2) [warning]
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.

Drush was attempting to connect to :
PHP configuration : /etc/php5/fastcgi/php.ini
Drupal Root : /data/drupal
Drupal version : 6.14
Site Path : sites/default
Site URI : http://default
Database Driver : mysqli
Database Hostname : localhost
Database Username : #####
Database Name : drupal
Database Password : #####

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.

Drush command could not be completed.

ls -al /var/cache/mysql/mysql.sock /var/run/mysql/mysql.sock
/bin/ls: cannot access /var/run/mysql/mysql.sock: No such file or directory
srwxrwxrwx 1 mysql mysql 0 2009-12-23 08:53 /var/cache/mysql/mysql.sock

ln -sf /var/cache/mysql/mysql.sock /var/run/mysql/mysql.sock
drush updatedb
No database updates required [success]
Finished performing updates. [ok]

so, the symlink is a workaround, but the solution should use what php.ini 'says' to use ...

pvhee’s picture

Looking for a solution to this problem as well. I am using drush with MAMP mysql socket and don't wont to symlink it as I also need to have the other mysql socket.

deviantintegral’s picture

Version: 6.x-2.0-alpha2 »
Status: Postponed (maintainer needs more info) » Active

This can happen if the wrong php binary is being called. For example, I just upgraded to MAMP 1.9, which includes both php 5.2 and php 5.3. Check the drush bash script to see what PHP is being called.

I changed the path to "/Applications/MAMP/bin/php5.2/bin/php" and all is working (yes, I'll look / file an issue :).

greg.1.anderson’s picture

hershel’s picture

EDITED: I am not sure if what I wrote in my comment to this thread was correct so I have moved my case to a separate issue: http://drupal.org/node/826816 and removed what was in this comment.

s4j4n’s picture

I have drush using MAMP's php but for the command drush sql-dump drush is using the default system mysqldump in $PATH (as opposed to MAMP's) and not using the socket listed in MAMP's php.ini file.

See my comment here for more details.

greg.1.anderson’s picture

Um, alias drush to set a reasonable PATH every time? We could have a setting for which mysqldump to use, but would we then also have a setting for which rsync to use, etc.? This sort of facility would just be duplicating what the PATH is already (in theory) supposed to be doing for you...

My opinion; I'll let Moshe set policy.

moshe weitzman’s picture

Status: Active » Closed (works as designed)

agree with greg. use $PATH in your shell.

Kjartan’s picture

Component: Code » Base system (internal API)
Category: feature » bug
Status: Closed (works as designed) » Needs review
FileSize
1.23 KB

Drupal 7.x lets you configure a unix_socket in settings.php and respects this. Drush 4.5 and 5.x does not.

Here is a patch against Drush 7x-4.5 that makes it behave correctly for my use-cases, but I'm not familiar enough with the code base to actually feel confident that it covers all functionality. I'd imagine there needs to be some extra code to have it print the defaults.

moshe weitzman’s picture

Welcome back!

Patch does not apply to drush5. If possible, please roll a version for that.

Next step would be to get sql-connect command working. Without that, many commands like sql-sync will fail when run on remote hosts.

Secondarily, add unix_socket to the drush status output. See http://api.drush.org/api/function/_core_site_status_table/5.x

Kjartan’s picture

Status: Needs review » Needs work

I'll try and get something sorted tomorrow. I haven't really used the sql-* commands before, but I'm sure I can manage to figure it out.

Kjartan’s picture

Status: Needs work » Needs review
FileSize
4.17 KB

Made a patch for 5.x which adds support for unix_socket. It defaults to use the socket over host:port if they are both configured. I've tested the normal command and sql-dump and they work fine with the sockets.

Note that Drupal core only adds special code to handle unix_socket for MySQL, but from my pgsql knowledge it should support sockets already if you set the socket as the host. Don't have a pgsql database to play around with atm, if someone could test that it would be nice. sqlite and sqlsrv don't support sockets to my knowledge so didn't add anything special there.

Also noticed that some of the Drush files are using tabs instead of spaces, my editor fixed the files I was editing but I can back that out if there is a reason they are in there. There are some other files affected so you might want to look into that.

moshe weitzman’s picture

Status: Needs review » Patch (to be ported)

Seems to work. Committed to master. If you are able to reroll for 4.x, I will commit there too. Thanks.

Kjartan’s picture

I noticed that in 5.x you have added site-install command that accepts a --db-url command. It is probably a new issue, but that should probably be extended to support a socket instead of host. I'd have to look at the implementation to confirm if sockets are supported or not, will try to do that while I port this patch to 4.x. Just making a note of it here so I remember.

Kjartan’s picture

Status: Patch (to be ported) » Needs review
FileSize
3.26 KB

Here is a patch for 4.x, including the fix by Greg for uninitialized variable error.

Before I look into the rest of the database connection code (--db-url, etc) I'm going to venture into Drupal core installer and database connections to see exactly what features are supported there (documented and undocumented). I'll open another issue for that stuff if I find anything that requires patching so feel free to close this one once the patch is committed.

moshe weitzman’s picture

Version: » All-versions-4.x-dev
YesCT’s picture

YesCT’s picture

Is this issue is the "real" solution to the problem in #1493022: improve readme and add "have command line use same php as webserver" for hint for "needs a higher bootstrap level to run" error (bootstrap error on MAMP with localhost instead of 127.0.0.1 in settings.php)?

joachim’s picture

Status: Needs review » Needs work

Patch no longer applies (to branch master). Parts of this patch (at least) seem to already be in the code.

greg.1.anderson’s picture

This is in 5.x master -- should be all in, not part in. Please provide details if there are still problems on the master branch.

This issue is currently open for backporting to 4.x -- no longer necessary, in my opinion, so I'd expect this could be closed if there are no issues with master.

jonhattan’s picture

Version: All-versions-4.x-dev »
Status: Needs work » Closed (fixed)

I neither think it's neccesary to backport to 4.x.

Reopen if #832472: Give advice on the "can't connect to local MySQL server through socket" error have any relation to this.