4
votes

Im trying to set Drush up for the first time. Im using Mamp and Mountain Lion. When I type 'drush' into the terminal I get a list of commands so it seems to be installed up OK.

Ive changed the default web directory folder in MAMP. I have many Drupal sites within folders within the web directory. So the url for one site is http://localhost:8888/omega/omegav3/ and another is http://localhost:8888/omega/omegav4/

By navigating to the site folder in the terminal I can then run a Drush command, however I get errors. When I download Views it does download the module to my sites/all/modules folder correctly, however it gives me some errors. When I try and enable the module it gives me more errors and doesn't enable the module.

unknown:omegav3 MYUSERNAME$ cd /Users/MYUSERNAME/Dropbox/sites/omega/omegav3 
unknown:omegav3 MYUSERNAME$ drush dl views
PDO::__construct(): [2002] No such file or directory (trying to connect via           [warning]
unix:///var/mysql/mysql.sock) environment.inc:523
Project views (7.x-3.7) downloaded to sites/all/modules/views.                        [success]
Project views contains 2 modules: views, views_ui.
unknown:omegav3 MYUSERNAME$ 
unknown:omegav3 MYUSERNAME$ drush en views
PDO::__construct(): [2002] No such file or directory (trying to connect via           [warning]
unix:///var/mysql/mysql.sock) environment.inc:523
Command pm-enable needs a higher bootstrap level to run - you will need to invoke     [error]
drush from a more functional Drupal environment to run this command.
The drush command 'en views' could not be executed.                                   [error]
Drush was not able to start (bootstrap) the Drupal database.                          [error]
Hint: This may occur when Drush is trying to:
 * bootstrap a site that has not been installed or does not have a configured
database. In this case you can select another site with a working database setup by
specifying the URI to use with the --uri parameter on the command line. See `drush
topic docs-aliases` for details.
 * connect the database through a socket. The socket file may be wrong or the php-cli
may have no access to it in a jailed shell. See http://drupal.org/node/1428638 for
details.

Drush was attempting to connect to: 
 Drupal version         :  7.23                                             
 Site URI               :  http://default                                   
 Database driver        :  mysql                                            
 Database username      :  root                                             
 Database name          :  omegav3                                          
 Default theme          :  garland                                          
 Administration theme   :  garland                                          
 PHP executable         :  /usr/bin/php                                     
 PHP configuration      :                                                   
 PHP OS                 :  Darwin                                           
 Drush version          :  6.1.0                                            
 Drush configuration    :                                                   
 Drush alias files      :                                                   
 Drupal root            :  /Users/MYUSERNAME/Dropbox/sites/omega/omegav3 
 Site path              :  sites/default                                    
 File directory path    :  sites/default/files                              


unknown:omegav3 MYUSERNAME$ 

It seems like an issue with Drush and MySQL but ive no idea how to fix this. Im very new to the command line and ive never installed anything like Drush before so im really struggling.

5

5 Answers

5
votes

Lets start with saying that i am not familiar with Drush at all. But looking at this from a MAMP perspective i think i know what is going on here.

The line PDO::__construct(): [2002] No such file or directory (trying to connect via [warning] unix:///var/mysql/mysql.sock) environment.inc:523 says it all.

By default MAMP is creating the MySQL socket in /Applications/MAMP/tmp/mysql/mysql.sock as stated on the MAMP launch page. However Drush is expecting the socket at var/mysql/mysql.sock.

Well there are two ways to fix this.

  1. Stop all MAMP servers. Edit the file /Applications/MAMP/bin/startMysql.sh, change --socket=/Applications/MAMP/tmp/mysql/mysql.sock into --socket=/var/mysql/mysql.sock. And don't forget to edit stopMysql.sh as well. This tells MAMP to store the socket elsewhere the next time it boots up the Mysql server.

  2. Create a symlink from /var/mysql/mysql.sock to /Applications/MAMP/tmp/mysql/mysql.sock see this post for more info on symlinks. MAMP will need to be running for you to do this, as the socket file is created dynamically.

Good luck!

3
votes

I had the same issue - what solved it for me was changing the database host in settings.php from "localhost" to "127.0.0.1".

3
votes

For me the mysql bin was not existant.

sudo ln -s /Applications/MAMP/Library/bin/mysql /usr/bin/mysql

Fixed it for me.

1
votes

As an alternative to answer #1, I would recommend you change your command-line MySQL to use MAMP's - this makes sure when you mysql from the command line, that works too. Edit your ~/.bash_profile and add the following line:

alias mysql='/Applications/MAMP/Library/bin/mysql'
1
votes

This worked for me

sudo mkdir /var/mysql sudo ln -s /Applications/MAMP/tmp/mysql/mysql.sock /var/mysql/mysql.sock