4

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.

4

5 回答 5

5

让我们先说我根本不熟悉 Drush。但是从 MAMP 的角度来看,我想我知道这里发生了什么。

这条线 PDO::__construct(): [2002] No such file or directory (trying to connect via [warning] unix:///var/mysql/mysql.sock) environment.inc:523说明了一切。

默认情况下,MAMP 正在创建 MySQL 套接字,/Applications/MAMP/tmp/mysql/mysql.sock如 MAMP 启动页面所述。然而,Drush 期望套接字位于var/mysql/mysql.sock.

那么有两种方法可以解决这个问题。

  1. 停止所有 MAMP 服务器。编辑文件/Applications/MAMP/bin/startMysql.sh,更改--socket=/Applications/MAMP/tmp/mysql/mysql.sock--socket=/var/mysql/mysql.sock. 并且不要忘记编辑 stopMysql.sh 。这告诉 MAMP 在下次启动 Mysql 服务器时将套接字存储在其他地方。

  2. 创建符号链接/var/mysql/mysql.sock/Applications/MAMP/tmp/mysql/mysql.sock查看帖子以获取有关符号链接的更多信息。您需要运行 MAMP 才能执行此操作,因为套接字文件是动态创建的。

祝你好运!

于 2013-10-13T10:17:39.930 回答
3

对我来说,mysql bin 不存在。

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

为我修好了。

于 2014-10-09T10:47:25.143 回答
3

我遇到了同样的问题 - 为我解决的问题是将 settings.php 中的数据库主机从“localhost”更改为“127.0.0.1”。

于 2014-07-21T09:48:14.497 回答
1

作为回答 #1 的替代方案,我建议您将命令行 MySQL 更改为使用 MAMP - 这可以确保当您从命令行执行 mysql 时,它也可以工作。编辑您的 ~/.bash_profile 并添加以下行:

alias mysql='/Applications/MAMP/Library/bin/mysql'
于 2013-10-14T14:28:11.400 回答
1

这对我有用

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

于 2014-01-22T11:44:02.080 回答