Drush无法在MAMP上连接到MySQL?

Eva*_*nss 4 macos mamp drupal drush

我正在尝试第一次设置Drush。我正在使用Mamp和Mountain Lion。当我在终端中输入'drush'时,我会看到命令列表,因此似乎可以安装。

我已经更改了MAMP中的默认Web目录文件夹。我在Web目录的文件夹内有许多Drupal站点。因此,一个网站的网址http://localhost:8888/omega/omegav3/http://localhost:8888/omega/omegav4/

通过导航到终端中的站点文件夹,我可以运行Drush命令,但是会出现错误。当我下载Views时,确实会将模块正确下载到我的sites / all / modules文件夹中,但是它给了我一些错误。当我尝试启用该模块时,它给我带来了更多的错误,并且没有启用该模块。

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$ 
Run Code Online (Sandbox Code Playgroud)

Drush和MySQL似乎是一个问题,但我不知道如何解决此问题。我对命令行非常陌生,而且我之前从未安装过像Drush这样的东西,因此我真的很挣扎。

小智 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 /Applications/MAMP/tmp/mysql/mysql.sock按照MAMP启动页面中的说明创建MySQL套接字。但是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才能执行此操作。

祝好运!