Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
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.
Comment | File | Size | Author |
---|---|---|---|
#17 | drush_support_unix_socket-4.x-437642.patch | 3.26 KB | Kjartan |
#14 | drush_support_unix_socket-437642.patch | 4.17 KB | Kjartan |
#11 | drush_mysq_socket.diff | 1.23 KB | Kjartan |
Comments
Comment #1
moshe weitzman CreditAttribution: moshe weitzman commentedHow does regular drupal let you use specify socket file?
Comment #2
z.stolar CreditAttribution: z.stolar commented#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?
Comment #3
PGNetDev CreditAttribution: PGNetDev commentedi'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 ...
Comment #4
pvhee CreditAttribution: pvhee commentedLooking 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.
Comment #5
deviantintegral CreditAttribution: deviantintegral commentedThis 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 :).
Comment #6
greg.1.anderson CreditAttribution: greg.1.anderson commentedSee also #801668: Add an option in drushrc.php to select the mysql socket to use
Comment #7
hershel CreditAttribution: hershel commentedEDITED: 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.
Comment #8
s4j4n CreditAttribution: s4j4n commentedI 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.
Comment #9
greg.1.anderson CreditAttribution: greg.1.anderson commentedUm, 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.
Comment #10
moshe weitzman CreditAttribution: moshe weitzman commentedagree with greg. use $PATH in your shell.
Comment #11
Kjartan CreditAttribution: Kjartan commentedDrupal 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.
Comment #12
moshe weitzman CreditAttribution: moshe weitzman commentedWelcome 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
Comment #13
Kjartan CreditAttribution: Kjartan commentedI'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.
Comment #14
Kjartan CreditAttribution: Kjartan commentedMade 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.
Comment #15
moshe weitzman CreditAttribution: moshe weitzman commentedSeems to work. Committed to master. If you are able to reroll for 4.x, I will commit there too. Thanks.
Comment #16
Kjartan CreditAttribution: Kjartan commentedI 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.
Comment #17
Kjartan CreditAttribution: Kjartan commentedHere 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.
Comment #18
moshe weitzman CreditAttribution: moshe weitzman commentedComment #19
YesCT CreditAttribution: YesCT commented#1011932: Support unix_socket in D7 $databases var in settings.php marked as a duplicate of this issue.
Comment #20
YesCT CreditAttribution: YesCT commentedIs 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)?
Comment #21
joachim CreditAttribution: joachim commentedPatch no longer applies (to branch master). Parts of this patch (at least) seem to already be in the code.
Comment #22
greg.1.anderson CreditAttribution: greg.1.anderson commentedThis 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.
Comment #23
jonhattanI 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.